【发布时间】:2012-04-04 21:48:19
【问题描述】:
这是我编写的一个包含地址信息的构造函数,但我在最后一部分遇到了问题,我必须返回一个包含姓名、地址、城市、州邮政编码的字符串。正确的写法是什么?
公开课地址{
private String name;
private String address;
private String state;
private String city;
private String zipcode;
public Address(String name, String address, String state, String city, String zipcode){
this.name = name;
this.address = address;
this.state = state;
this.city = city;
this.zipcode = zipcode;
}
public Address(){
name = "occupant";
address = " ";
state = " ";
city = " ";
zipcode = " ";
}
public void setAddress(String Address){
this.address = Address;
}
public void setstate(String state){
this.state= state;
}
public void setcity(String city){
this.city = city;
}
public void setzipcode(String code){
this.zipcode = code;
}
public String getaddress(){ // Return string that contains name and address and city and zipcode
return getaddress() + " " + return state + " " + return city + " " + return code;
}
}
【问题讨论】:
-
你需要一整串吗?或者它可能是一个字符串数组?还有你为什么在
getaddress()里面打电话getaddress()????