7. Nested Classes and Interfaces

7.1 (e)

The code will compile without error and will print 123 when run. An instance of the Outer outer will be created and the field secret will be initialized to 123. A call to the createInner() method will return a reference to a newly created Inner instance. This object is an instance of a non-static member class and is associated with the outer instance. This means that an object of a non-static member class has access to the members within the outer instance. Since the Inner class is nested in the class containing the field secret, this field is accessible to the Inner instance, even though the field secret is declared private.

7.2 (b) and (e)

A static member class is in many respects like a top-level class, ...

Get Programmer's Guide to Java™ Certification, A: A Comprehensive Primer, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.