fork download
  1. class A {
  2. private int field;
  3.  
  4. A(int value) {
  5. this.field = value;
  6. }
  7.  
  8. public void sayField() {
  9. System.out.println("(A) field == " + this.field);
  10. }
  11. }
  12.  
  13. class B extends A {
  14. private int field;
  15.  
  16. B(int aValue, int bValue) {
  17. super(aValue);
  18. this.field = bValue;
  19. }
  20.  
  21. @Override
  22. public void sayField() {
  23. super.sayField();
  24. System.out.println("(B) field == " + this.field);
  25. }
  26. }
  27.  
  28. class Ideone
  29. {
  30. public static void main (String[] args) throws java.lang.Exception
  31. {
  32. B b = new B(1, 2);
  33. b.sayField(); // "(A) field == 1" then "(B) field == 2"
  34. }
  35. }
  36.  
Success #stdin #stdout 0.09s 320576KB
stdin
Standard input is empty
stdout
(A) field == 1
(B) field == 2