June 2025
Intermediate to advanced
1129 pages
53h
English
A non-static nested type is an inner type that is comparable to an object property. Let’s declare an inner class named Room in House with the following example code:
class AlmondJoy { String name = "Almond Joy"; private int introduced = 1946; class Coconut { void print() { System.out.println( name ); System.out.println( introduced ); } }}
Listing 10.3 src/main/java/com/tutego/insel/nested/AlmondJoy.java (Snippet)
An instance of the Coconut class has access to all members of AlmondJoy , including its private members.
To create an instance of Coconut, an instance of the outer class must exist first. One important difference in this regard relates to the static ...
Read now
Unlock full access