请各位帮忙看看~问题出在哪里呀?
代码
class Address{
private String country;
private String province;
private String city;
private String street;
private String code;
public Address(String cou,String pro,String cit,String str,String cod){
this.setCountry(cou);
this.setProvince(pro);
this.setCity(cit);
this.setStreet(str);
this.setCode(cod);
}
public String total(){
return "地址信息为: /n"+
"国家" + this.getCountry()+
"省" + this.getProvince()+
"市" + this.getCity() +
"街道" + this.getStreet()+
"邮编" + this.getCode();
}
public void setCountry(String cou){
country=cou;
}
public void setProvince(String pro){
province=pro;
}
public void setCity(String cit){
city=cit;
}
public void setStreet(String str){
street=str;
}
public void setCode(String cod){
code=cod;
}
public String getCountry(){
return country;
}
public String getProvince(){
return province;
}
public String getCity(){
return city;
}
public String getStreet(){
return street;
}
public String getCode(){
return code;
}
}
public class Test{
public static void main(String args[]){
Test a = new Address("中国","北京","朝阳","平乐园",100000);
a.total();
}
}
编译时抛错:
C:\>javac Test.java
Test.java:68: cannot find symbol
symbol : constructor Address(java.lang.String,java.lang.String,java.lang.String
,java.lang.String,int)
location: class Address
Test a = new Address("中国","北京","朝阳","平乐园",100000);
^
Test.java:69: cannot find symbol
symbol : method total()
location: class Test
a.total();
^
2 errors
Test a 改成 Address a
另外
public Address(String cou,String pro,String cit,String str,String cod)
这里是5个String, 不是4个String+1个int, 所以这里
String cod 改成 int cod
或者
a = new Address("中国","北京","朝阳","平乐园",100000);
改成
a = new Address("中国","北京","朝阳","平乐园","100000");
1.a的声明对象错误,不是Test,是 Address
2.Address的构造函数,为5个字符串,你在创建的时候,最后一位是数字。
错误
Test a = new Address("中国","北京","朝阳","平乐园",100000);
改成
Address a = new Address("中国","北京","朝阳","平乐园","100000");本回答被提问者采纳
symbol : constructor
找不到构造器
cannot find symbol
symbol : method total()
找不到方法total()标志
不是Test a = new Address("中国","北京","朝阳","平乐园",100000);...
是Address a=new Address("中国","北京","朝阳","平乐园",100000);吧
还有LZ 你还是找个ide比如netbeans来写代码吧,就不用在这些小问题上浪费时间了.
改成
Address a = new Address("中国","北京","朝阳","平乐园",100000);