Question 1
What is the output of the following program? ```java public class Main { static class Box { String label() { return "boxed"; } } public static void main(String[] args) { Box b = new Box(); System.out.println(b.label()); } } ```
A. An exception is thrown at runtime
Nothing in the code throws; construction and the method call are routine.
B. boxedCorrect answer
Correct: the nested class is instantiated directly and its instance method returns this string.
C. Compilation fails because static classes cannot have instance methods
Static nesting refers to the class not capturing an outer instance; it says nothing against declaring instance methods.
D. Compilation fails because Box needs an enclosing instance
Requiring an enclosing instance is the rule for non-static member (inner) classes, not static ones.
Explanation
A static nested class is an independent type that merely lives inside another; it needs no enclosing instance and can hold ordinary instance methods. Constructing it with new and calling its method behaves like any top-level class.