OCA Java SE 8 Mock Exam Review - OCA Mock Question 10








Question

Given the following class definitions:

    public class BaseMain { 
       public BaseMain() { 
          System.out.println("BaseMain constructor"); 
       } 
         
       public void someMethod() { 
          System.out.println("BaseMain someMethod"); 
       } 
    } 

    class Main extends BaseMain { 
       public Main() { 
          System.out.println("Main constructor"); 
       } 
         
       public void someMethod() { 
          // comment 
          System.out.println("Main someMethod"); 
       }     
       public static void main(String args[]) { 
          Main b = new Main(); 
          b.someMethod(); 

       } 
    } 

What statement is needed at the comment line to generate the following output:

         BaseMain constructor 
         Main constructor 
         BaseMain someMethod 
         Main someMethod 
  1. super();
  2. super().someMethod;
  3. super.someMethod();
  4. someMethod();
  5. None of the above




Answer



c

Note

The first answer is used only as the first statement of a constructor. The second answer generates a syntax error. The fourth option results in unbounded recursion.