package lianxi;
/*
* 要求:编写并且测试一个类,返回国家,省,城市 街道,并且能返回完整的地址信息
* 思路:定义一个类,里面有构造方法初始化,里面有国家,省,城市,街道
* 定义方法获取
*/
public class TestDemo7 {
public static void main(String[] args) {
Adress ad=new Adress("中国","辽宁","沈阳","MJHD","10000");
System.out.println(ad);
}
}
class Adress
{
private String national;
private String provincial;
private String city;
private String street;
private String zipcode;
public /*void*/ Adress(String national, String provincial,String city,String street,String zipcode){
//这为什么不能放void或者String呢??
this.national=national;
this.provincial=provincial;
this.city=city;
this.street=street;
this.zipcode=zipcode;
}
public String toString(){
return "国家:"+national+"省份:"+provincial+"城市:"+city+"街道:"+street+"邮编:"+zipcode;
}
}
问题在中间红字 |
|