java开发实战经典(第二版)P157 5-1

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

猜你喜欢

转载自blog.csdn.net/javaxiaobaismc/article/details/81150917
5-1