Java OCA OCP Practice Question 2595

Question

Which of the following can be inserted in main?

public class Outer { 
   class Inner { } 
    
   public static void main(String[] args) { 
      // INSERT CODE HERE 
   } } 
  • A. Inner in = new Inner();
  • B. Inner in = Outer.new Inner();
  • C. Outer.Inner in = new Outer.Inner();
  • D. Outer.Inner in = new Outer().Inner();
  • E. Outer.Inner in = new Outer().new Inner();
  • F. Outer.Inner in = Outer.new Inner();


E.

Note

This is a member inner class.

It needs to be created using an instance of the outer class.

The syntax looks weird, but it creates an object of the outer class and then an object of the inner class from it.




PreviousNext

Related