Accessing Nested Classes from Outside

Now that you have seen examples of the various types of nested classes, let's look at how a nested class can be accessed from outside the enclosing class.

A Static Nested Class Example

Recall that in Listing 5.2, the variable declaration used this syntax that starts with the name of the enclosing class:

12.  Bubble.BubTimer timer ;

The constructor call also used the name of the enclosing class.

17.     timer = new Bubble.BubTimer( this );

Now we are going to contrast that with how member inner class objects are created and named.

Using a Member Inner Class Object

The important thing to remember about inner classes is that an inner class object must always be associated with an instance of the enclosing class. ...

Get Java 2™ Programmer Exam Cram™ 2 (Exam CX-310-035) 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.