Friday, December 9, 2011

Class Definition » super

Variable in subclass hides the variable in the super class
class {
  int i;
}

class extends {
  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(12);

    subOb.show();
  }
}
 
 
  http://www.java2s.com/Tutorial/Java/0100__Class-Definition/Catalog0100__Class-Definition.htm

No comments:

Post a Comment