Java 编写并测试一个代表地址的Address类,并可以返回完整的地址信息

编写一个代表地址的Address类,地址信息由国家,省份,城市,街道,邮编组成,并且可以返回完整的地址信息。

class Address{
    private String nation,province,city,street,code;
    public Address(String nation,String province,String city,String street,String code){
        this.nation=nation;
        this.province=province;
        this.city=city;
        this.street=street;
        this.code=code;
    }
    public void print(){
        System.out.println("地址信息为:"+this.nation+this.province+this.city+this.street+" "+"邮政编号:"+this.code);
    }
}

public class AddressTest{
    public static void main(String args[]){
        Address a=new Address("中国","广东省","东莞市","松山湖114号","522101");
        a.print();
    }
}

猜你喜欢

转载自blog.csdn.net/weixin_42895133/article/details/81780573