1 public class FieldTest { 2 private int a; 3 protected int b = 123; 4 protected FieldTestClass c; 5 protected FieldTestClass d = null; 6 public FieldTestClass e = new FieldTestClass(456); 7 public FieldTestClass f = new FieldTestClass(b + e.a); 8 public static FieldTestClass g; 9 public static FieldTestClass h = new FieldTestClass(789); 10 11 public static void main(String[] args) { 12 if (FieldTest.h != null && FieldTest.h.a == 789) { 13 System.out.println("FieldTest.h.a correct: " + FieldTest.h.a); 14 } else { 15 System.out.println("FieldTest.h.a failed!"); 16 } 17 FieldTest test = new FieldTest(); 18 if (test.h != null && test.h.a == 789) { 19 System.out.println("test.h.a correct: " + test.h.a); 20 } else { 21 System.out.println("test.h.a failed!"); 22 } 23 if (test.e != null && test.e.a == 456) { 24 System.out.println("test.e.a correct: " + test.e.a); 25 } else { 26 System.out.println("test.e.a failed!"); 27 } 28 if (test.f != null && test.f.a == 579) { 29 System.out.println("test.f.a correct: " + test.f.a); 30 } else { 31 System.out.println("test.f.a failed!"); 32 } 33 } 34 } 35 36 class FieldTestClass { 37 public int a; 38 39 public FieldTestClass(int a) { 40 this.a = a; 41 } 42 } 43 44 // vim: tabstop=4 expandtab shiftwidth=4