Java OCA OCP Practice Question 614

Question

Consider the following code in Main.java file:

package p; /*from   www.j  a va 2 s  .c o  m*/
private class MyClass extends java.util.HashMap { 
   public MyClass (){ 
      super (100); 
      System .out.println ("MyClass created"); 
    } 
} 
public class Main extends MyClass{ 
   public Main (){ 
      System .out.println ("Main created"); 
    } 
   public static void main (String [] args){ new Main ();  } 
} 

What will be the output when Main is run?

Select 1 option

  • A. "Main created" as well as "MyClass created".
  • B. It will not compile because HashMap is a final class.
  • C. Only "Main created" will be printed.
  • D. Only "MyClass created" will be printed.
  • E. None of the above are correct.


Correct Option is  : E

Note

The file will not compile because MyClass is a top level class and private is not a valid access modifier for a top level class. private can be applied to an inner class.




PreviousNext

Related