关闭

统计实例化对象个数

286人阅读 评论(0) 收藏 举报

class User{
private  String name;
private String password;
private  static int count;

public String getName(){
return name;
}
public void setName(String name){
this.name=name;
}
public  String getPasssword(){
return password;
}
public void setPassword(String password){
this.password=password;
}


User(){
count++;
}
User(String name){
super();
this.name=name;
count++;
}
User(String name, String password){
super();
this.name=name;
this.password=password;

count++;
}

public String toString(){
return "姓名"+name+"口令"+password;
}
public void print(){
System.out.println("姓名"+name+"口令"+password);
}
public void count(){
System.out.println("用户个数"+(count-1));
}


}


public class ExampleDemo1 {
public static void main(String args[]){
User d=new User("阿黄","黄色");
User d1=new User("阿黑","黑色");
d.print();
d1.print();
new User().count();

}
}


0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    express yourself

    Life is a pleasure trip designed by you

    居敬持志,循序致精

    为善去恶致良知

    个人资料
    • 访问:84401次
    • 积分:2040
    • 等级:
    • 排名:千里之外
    • 原创:100篇
    • 转载:136篇
    • 译文:4篇
    • 评论:6条
    最新评论