static 型名 変数名 |
01 class C { 02 static int s = 0; // 静的変数sの宣言 03 int n = 0; // インスタンス変数nの宣言 04 public void countUp() { 05 s++; 06 n++; 07 } 08 public void show() { 09 System.out.println("s= "+s+" \tn= "+n); 10
}
12 class Example3 { 13 public static void main(String[] args) { 14 C a = new C(); 15 System.out.println("a"); 16 a.show(); 17 a.countUp(); 18 a.show(); 19 a.countUp(); 20 a.show(); 21 C b = a; 22 System.out.println("b"); 23 b.show(); 24 C c = new C(); 25 System.out.println("c"); 26 c.show(); 27 c.countUp(); 28 c.show(); 29 System.out.println("a"); 30 a.show(); 31 System.out.println("s="+C.s+",\t"+a.s); 32 } 33 } |