5.1 编写并测试一个代表地址的Address类,地址信息由国家、省份、城市、街道、邮编组成,并可以返回完整的地址信息。
package book;
public class JiOu {
private String country;
private String city;
private String street;
private String province;
private String postcode;
@Override
public String toString() {
return "国家:" + this.country + "\n" + "省份:" + this.province + "\n" + "城市:" + this.city + "\n" + "街道:"
+ this.street + "\n" + "邮编:" + this.postcode;
}
public JiOu(String country, String city, String street, String province, String postcode) {
this.country = country;
this.city = city;
this.street = street;
this.province = province;
this.postcode = postcode;
}
public static void main(String[] args) {
JiOu address = new JiOu("中国", "广州", "迎龙路", "广东", "510520");
System.out.println(address);
}
}
运行结果为:
国家:中国
省份:广东
城市:广州
街道:迎龙路
邮编:510520