您的位置:首页 > 其它

修改static中成员变量的值

2016-06-13 18:55 232 查看

class person{

    String name;

    int age;

    static String country;

    public person(){}

    public person(String name,int age){

        this.name=name;

        this.age=age;

    }

     public person(String name,int age,String country){

        this.name=name;

        this.age=age;

        this.country=country;

    }

    public void show(){

        System.out.println("姓名是:  "+name+"   年龄  "+age+"   国家   "+country);

    }

}

class persontest{

    public static void main(String [] args){

        person p1=new person("大致",11,"中国");

        p1.show();

        person p2=new person("小明",11);

        p2.show();

        person p3=new person("小刚",11);

        p3.show();

        p3.country="美国";

        p1.show();

        p2.show();

        p3.show();

    }

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: