Which class definition compiles?
A.
B.
C.
D.
Which class definition compiles?
A.
B.
C.
D.
The correct answer is B. Option A does not compile because a method-local inner class cannot be declared as public. Option C does not compile because it attempts to reference a non-static member variable ('bno') from a static context, which is not allowed. Option D does not compile because for the anonymous class implementing the 'Moveable' interface, the 'move' method implementation should be declared as public. Option B is correct because it follows all Java syntax rules properly: an abstract class can be extended by a private class, and the instance variable 'sCard' is properly instantiated with an instance of 'SoundCard'.
The Correct Answer is B D only compiles when "public" is added to "void move()" in the definition of the anonymous class
I don't know how this is possible but B and D both compile... I tested
Answer is D, tested class Vehicle{ int id; public void start(){ // compile error public class Engine{ int eNo = id;} } } class Computer{ // compile error private Card card = new SoundCard(); private abstract class Card{} // compile error private class SoundCard extends Card{} } class Block{ int bno; static class Counter{ int locator; //compile error Counter(){ locator = bno;} } } class Product{ interface Moveable{void move();} Moveable m = new Moveable() { @Override public void move() { } }; }
B is correct. Tested. A doesn't compile because method class can't be public, C doesn't compile because you can't reference non-static members from static context and D doesn't compile because move method must be public.
Answer : B
Answer is B.
B, tested