fork download
  1. class SOFieldAccessQuestion {
  2.  
  3. static class B {
  4. int vf;
  5. static int sf;
  6.  
  7. B(int i) {
  8. vf = i;
  9. sf = i + 1;
  10. }
  11. }
  12.  
  13. static class C extends B {
  14. int vf;
  15. static int sf;
  16. C(int i) {
  17. super(i+20);
  18. vf = i;
  19. sf = i + 2;
  20. }
  21. }
  22.  
  23. public static void main(String[] args) {
  24.  
  25. // Is it Okay to create an instance of static nested class?
  26.  
  27. C c1 = new C(100);
  28. B b1 = c1;
  29.  
  30. System.out.println("B.sf = " + B.sf + ", b1.sf = " + b1.sf);
  31. System.out.println("C.sf = " + C.sf + ", c1.sf = " + c1.sf);
  32.  
  33. System.out.println("b1.vf = " + b1.vf);
  34. System.out.println("c1.vf = " + c1.vf);
  35. }
  36.  
  37. }
  38.  
Success #stdin #stdout 0.08s 380224KB
stdin
Standard input is empty
stdout
B.sf = 121, b1.sf = 121
C.sf = 102, c1.sf = 102
b1.vf = 120
c1.vf = 100