Test a Method Call with the super Qualifier - Java Object Oriented Design

Java examples for Object Oriented Design:Inheritance

Description

Test a Method Call with the super Qualifier

Demo Code

class MySuper {/*from   w  w w. j  a  va 2 s.  co  m*/
  public void print() {
    System.out.println("Inside AOSuper.print()");
  }
}
class MySub extends MySuper {
  public void print() {
    // Call print() method of AOSuper class 
    super.print();

    // Print a message 
    System.out.println("Inside AOSub.print()");
  }

  public void callOverridenPrint() {
    // Call print() method of AOSuper class 
    super.print();
  }
}


public class Main {
  public static void main(String[] args) {
    MySub aoSub = new MySub();
    aoSub.print();
    aoSub.callOverridenPrint();
  }
}

Result


Related Tutorials