1. 程式人生 > >類的靜態欄位和建構函式

類的靜態欄位和建構函式

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。