标签:设置 country pac main string private 国家 城市 ret
编写并测试一个代表地址的Address类,地址信息由国家 省份 城市 街道 邮编 组成,并可以返回完整的地址信息。
package test1; class Address{ private String Country; private String Province; private String City; private String Street; private String Zipcode; public Address(String Country,String Province,String City,String Street,String Zipcode){ this.setCountry(Country); this.setProvince(Province); this.setCity(City); this.setStreet(Street); this.setZipcode(Zipcode); } public void setCountry(String c){ //设置国家 省份 城市 街道 邮编 Country=c; } public void setProvince(String p){ Province=p; } public void setCity(String ci){ City=ci; } public void setStreet(String s){ Street=s; } public void setZipcode(String z){ Zipcode=z; } public String getCountry(){ //返回国家 省份 城市 街道 邮编 return Country; } public String getProvince(){ return Province; } public String getCity(){ return City; } public String getStreet(){ return Street; } public String getZipcode(){ return Zipcode; } public void print(){ System.out.println("国家:"+getCountry()+"\n"+"省份:"+getProvince()+"\n"+"城市:"+getCity() +"\n"+"街道:"+getStreet()+"\n"+"邮编:"+getZipcode()); } } public class Test01 { public static void main (String args[]){ Address A =new Address("中国", "河南", "林州", "振林街", "111222"); A.print(); } }
标签:设置 country pac main string private 国家 城市 ret
原文地址:https://www.cnblogs.com/ivan999/p/10415847.html