(JAVA初学者)谁能告诉我这个代码最后为什么System.out.println(add.getInfo()); 里必须要用add啊
//编写并测试一个代表地址的Address类,包括以下属性://国家、省份、城市、街道、邮编//可以从此地址类中得到一个完整的地址信息classAddress{priva...
//编写并测试一个代表地址的Address类,包括以下属性:
//国家、省份、城市、街道、邮编
//可以从此地址类中得到一个完整的地址信息
class Address{
private String national;
private String province;
private String city;
private String street;
private String zipcode;
public Address(){}
public Address(String n,String p,String c,String s,String z){
this.setNational(n);
this.setProvince(p);
this.setCity(c);
this.setStreet(s);
this.setZipcode(z);
}
public String getInfo(){
return"地址信息:" + "\n" +
"\t|-国家:" + this.getNational() +"\n" +
"\t|-省份:" + this.getProvince() + "\n" +
"\t|-城市:" + this.getCity() + "\n" +
"\t|-街道:" + this.getStreet() + "\n" +
"\t|-邮编:" + this.getZipcode() ;
}
public void setNational(String n){
national = n;
}
public void setProvince(String p){
province = p;
}
public void setCity(String c){
city = c;
}
public void setStreet(String s){
street = s;
}public void setZipcode(String z){
zipcode = z;
}
public String getNational(){
return national;
}
public String getProvince(){
return province;
}
public String getCity(){
return city;
}
public String getStreet(){
return street;
}
public String getZipcode(){
return zipcode;
}
};
public class Zuoye1{
public static void main(String args[]){
Address add = new Address("中国","北京","北京市","西城区","100088");
System.out.println(add.getInfo());
}
}; 展开
//国家、省份、城市、街道、邮编
//可以从此地址类中得到一个完整的地址信息
class Address{
private String national;
private String province;
private String city;
private String street;
private String zipcode;
public Address(){}
public Address(String n,String p,String c,String s,String z){
this.setNational(n);
this.setProvince(p);
this.setCity(c);
this.setStreet(s);
this.setZipcode(z);
}
public String getInfo(){
return"地址信息:" + "\n" +
"\t|-国家:" + this.getNational() +"\n" +
"\t|-省份:" + this.getProvince() + "\n" +
"\t|-城市:" + this.getCity() + "\n" +
"\t|-街道:" + this.getStreet() + "\n" +
"\t|-邮编:" + this.getZipcode() ;
}
public void setNational(String n){
national = n;
}
public void setProvince(String p){
province = p;
}
public void setCity(String c){
city = c;
}
public void setStreet(String s){
street = s;
}public void setZipcode(String z){
zipcode = z;
}
public String getNational(){
return national;
}
public String getProvince(){
return province;
}
public String getCity(){
return city;
}
public String getStreet(){
return street;
}
public String getZipcode(){
return zipcode;
}
};
public class Zuoye1{
public static void main(String args[]){
Address add = new Address("中国","北京","北京市","西城区","100088");
System.out.println(add.getInfo());
}
}; 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询