题目是这样的:编写并测试一个代表地址的Address类,地址由国家,省份,城市,街道,邮编组成,并可以返回完整的信息。
我的代码如下,可是会产生一个很难懂的错误,麻烦大家帮小弟解决下:
class Address
{
private String country;
private String province;
private String city;
private String street;
private int pcode;
public Address(String country,String province,String city,String street,int pcode)
{
this.country=country;
this.province=province;
this.city=city;
this.street=street;
this.pcode=pcode;
}
public String getcountry()
{
return this.country;
}
public String getprovince()
{
return this.province;
}
public String getcity()
{
return this.city;
}
public String getstreet()
{
return this.street;
}
public int getpcode()
{
return this.pcode;
}
}
public class TestAddress
{
public static void main(String[] args)
{
Address add=New Address("China","jiangxi","nanchang","nanjing road",338027);
System.out.println("country:"+add.getcountry());
System.out.println("province:"+add.getprovince());
System.out.println("city:"+add.getcity());
System.out.println("street:"+add.getstreet());
System.out.println("post code:"+add.getpcode()); }
}
我的代码如下,可是会产生一个很难懂的错误,麻烦大家帮小弟解决下:
class Address
{
private String country;
private String province;
private String city;
private String street;
private int pcode;
public Address(String country,String province,String city,String street,int pcode)
{
this.country=country;
this.province=province;
this.city=city;
this.street=street;
this.pcode=pcode;
}
public String getcountry()
{
return this.country;
}
public String getprovince()
{
return this.province;
}
public String getcity()
{
return this.city;
}
public String getstreet()
{
return this.street;
}
public int getpcode()
{
return this.pcode;
}
}
public class TestAddress
{
public static void main(String[] args)
{
Address add=New Address("China","jiangxi","nanchang","nanjing road",338027);
System.out.println("country:"+add.getcountry());
System.out.println("province:"+add.getprovince());
System.out.println("city:"+add.getcity());
System.out.println("street:"+add.getstreet());
System.out.println("post code:"+add.getpcode()); }
}
Address add= new Address("China","jiangxi","nanchang","nanjing road",338027);
new 是小写的~~
getprovince
……
去看看基本的规范
其实你用debug 跟踪一下就知道那里错了
public String getUserId() {
return userId;
} public void setUserId(String userId) {
this.userId = userId;
}
New 改为 New
package的命名 package 的名字由全部小写的字母组成,例如:cn.mybole。
class和interface的命名 class和interface的名字由大写字母开头而其他字母都小写的单词组成,例如:Person,RuntimeException。
class变量的命名 变量的名字用一个小写字母开头,后面的单词用大写字母开头,例如:index,currentImage。
class方法的命名
方法的名字用一个小写字母开头,后面的单词用大写字母开头,例如:run(),getBalance()。
static final变量的命名 static final变量的名字所有字母都大写,并且能表示完整含义。例如:PI,PASSWORD。
参数的命名 参数的名字和变量的命名规范一致。
数组的命名 数组应该总是用这样的方式来命名:byte[] buffer。