Home » Java Programming » Inner Classes

Which constructs an anonymous inner class instance?

Correct Answer: System.out.println(new Runnable() {public void run() { }});

Explanation:

D is correct. It defines an anonymous inner class instance, which also means it creates an instance of that new anonymous class at the same time. The anonymous class is an implementer of the Runnable interface, so it must override the run() method of Runnable.


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.


← Previous Question Next Question→

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion