Variable in subclass hides the variable in the super class : super « Class Definition « Java Tutorial






class A {
  int i;
}

class B extends A {
  int i; // this i hides the i in A

  B(int a, int b) {
    super.i = a; // i in A
    i = b; // i in B
  }

  void show() {
    System.out.println("i in superclass: " + super.i);
    System.out.println("i in subclass: " + i);
  }
}

class UseSuper {
  public static void main(String args[]) {
    B subOb = new B(1, 2);

    subOb.show();
  }
}








5.23.super
5.23.1.Variable in subclass hides the variable in the super class