Which of the following statements are true? (Choose all that apply.)
new Outer().new Inner()
new Outer().new ActionListener()
new Inner()
MyInterface
can be constructed and returned from a method like this: 1. return new MyInterface(int x) { 2. int x; 3. public MyInterface(int x) { 4. this.x = x; 5. } 6. };
A.
Construction of a named and nonstatic inner class requires an instance of the enclosing class.
Often this enclosing instance is provided via the implied this reference, but an explicit reference can be used in front of the new operator.
Anonymous inner classes can be instantiated only at the same point they are declared, so B is illegal.
C is illegal because Inner is a nonstatic inner class, and so it requires a reference to an enclosing instance when it is constructed.
D is illegal because it is trying to use arguments to the constructor of an anonymous inner class that implements an interface.