类的静态字段和构造函数

package jiecheng;

public class sum {
public static int a=0;

int c;

public sum(int cc)

{

c=cc;

a++;

}

public int get()

{

return a;

}
}

package jiecheng;

public class D_X3 {
public static void main(String[] args)

{

//TODO Auto-generated method stub

//调用

sum one=new sum(2);

//sum tow=new sum(3);

sum three=new sum(3);

//输出

System.out.println(one.get());

}
}

测试结果为2。

posted @ 2018-10-20 11:18  Double晨  阅读(168)  评论(0编辑  收藏  举报