Java OCA OCP Practice Question 769


Which of the following lines of code that,

when inserted at line 1,

will make the overriding method in SubClass invoke the overridden method in MyBaseClass on the current object with the same parameter.

class MyBaseClass {
   public void print(String s) {
      System.out.println("MyBaseClass  :" + s);
   }/*ww w  .jav a  2s.  c  o  m*/

class Main extends MyBaseClass {
   public void print(String s) {
      System.out.println("Main  :" + s);
      // Line 1

   public static void main(String args[]) {
      Main sc = new Main();

Select 1 option

  • A. this.print (s);
  • B. super.print (s);
  • C. print (s);
  • D. MyBaseClass.print (s);

Correct Option is  : B


For Option B.

This is the right syntax to call the base class's overridden method.

There is no way call a method if it has been overridden more than once.

For Option D. print is not a static method.