class Foo { class Bar{ } } class Test { public static void main (String [] args) { Foo f = new Foo(); /* Line 10: Missing statement? */ } }
Option A, C and D all use incorrect syntax. A is incorrect because it doesn't use a reference to the enclosing class, and also because it includes both names in the new.
C is incorrect because it doesn't use the enclosing class name in the reference variable declaration, and because the new syntax is wrong.
D is incorrect because it doesn't use the enclosing class name in the reference variable declaration.
A is incorrect because it doesn't override the run() method, so it violates the rules of interface implementation.
B and C use incorrect syntax.
class Boo { Boo(String s) { } Boo() { } } class Bar extends Boo { Bar() { } Bar(String s) {super(s);} void zoo() { // insert code here } }
Option A is incorrect because it passes an int to the Boo constructor, and there is no matching constructor in the Boo class.
Option C is incorrect because it violates the rules of polymorphism—you cannot refer to a superclass type using a reference variable declared as the subclass type. The superclass is not guaranteed to have everything the subclass has.
Option D uses incorrect syntax.
Option A, B, D, and E are all incorrect because they don't follow the syntax rules described in the response for answer Option C.
Option A is incorrect because a method-local inner class does not have to be declared final (although it is legal to do so).
C and D are incorrect because a method-local inner class cannot be made public (remember-you cannot mark any local variables as public), or static.
public class MyOuter { public static class MyInner { public static void foo() { } } }
MyOuter.MyInner mi = m.new MyOuter.MyInner();
Option B is incorrect because it doesn't use the enclosing name in the new.
Option C is incorrect because it uses incorrect syntax. When you instantiate a nested class by invoking new on an instance of the enclosing class, you do not use the enclosing name. The difference between Option A and C is that Option C is calling new on an instance of the enclosing class rather than just new by itself.
Option D is incorrect because it doesn't use the enclosing class name in the variable declaration.
Option A is incorrect because static nested classes do not need (and can't use) a reference to an instance of the enclosing class.
Option C is incorrect because static nested classes can declare and define nonstatic members.
Option D is wrong because it just is. There's no rule that says an inner or nested class has to extend anything.
Copyright ©CuriousTab. All rights reserved.