Difficulty: Medium
Correct Answer: Boo f = new Bar() { };
Explanation:
Introduction / Context:
This question focuses on valid anonymous inner class creation expressions and constructor usage in inheritance hierarchies.
Given Data / Assumptions:
Concept / Approach:
An anonymous inner class can extend a concrete class or implement an interface. The syntax is new Type(args) { /* body */ }. The constructor arguments must match an existing constructor. The resulting instance type is an anonymous subclass of the specified type.
Step-by-Step Solution:
Verification / Alternative check:
Also valid would be Boo f = new Boo() { }; using Boo's no-arg constructor, but that option is not provided exactly as such.
Why Other Options Are Wrong:
They either use non-existent constructors or incorrect syntax for anonymous classes.
Common Pitfalls:
Supplying wrong constructor arguments for the chosen type, and confusing anonymous subclassing with named nested classes.
Final Answer:
Boo f = new Bar() { };
Discussion & Comments