Java OCA OCP Practice Question 2341

Question

Given the following definition of classes Outer and Inner, select options that can be inserted individually at //INSERT CODE HERE. (Choose all that apply.)

class Outer { 
    void aMethod() { 
        class Inner { 
            // INSERT CODE HERE 
        } 
    }  
} 
  • a protected Inner() {}
  • b final static String name = "abc";
  • c static int ctr = 10;
  • d private final void Inner() {}
  • e Outer outer = new Outer();
  • f Inner inner = new Inner();
  • g static void print() {}
  • h static final void print() {}


a, b, d, e, f

Note

You can define final static variables in a method local inner class, but you can't define non-final static variables, static methods, or static final methods.

You can define constructors with any access modifier in a local inner class.




PreviousNext

Related