静态变量查询类创建了多少个对象

源代码:

package demo;
import java.util.*;
class How {
public static int a=0;
public How(){
a++;
}
public int getValue(){
return a;
}
}
public class HowMany{
public static void main(String arges[]){
How a1 = new How();
System.out.println(a1.getValue());
How a2 = new How();
System.out.println(a2.getValue());
How a3 = new How();
System.out.println(a3.getValue());
}
}

posted @   ChanGeZ  阅读(144)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示