Game Development Reference
In-Depth Information
It is important to note if you use, for example, import
javafx.application.Application.Parameters to import a nested class,
you can reference that nested class within your class, using just the Parameters class
name, rather than the full class name path that shows your class's code how to travel
through a parent class to its nested class via the Application.Parameter
(ClassName.NestedClassName) dot notation syntax reference.
As you will see many times throughout this topic, Java methods can also be ac-
cessed using the dot notation. So, instead of using
ClassName.NestedClassName.MethodName , you could, if you had used the import
statement to import this nested class, simply use Nes-
tedClassName.MethodName . This is because the Java import statement has
already been used to establish the full reference path to this nested class, through its
containing class, and so you do not have to provide this full path reference for the com-
piler to know what code construct you are referring to!
Next, let's take a look at nonstatic nested classes, which are usually referred to as
Java inner classes.
Inner Classes: Different Types of Nonstatic Nested
Classes
Java inner classes are also nested classes, but they are not declared using the static
keyword modifier before the class keyword and class name, which is why they are
called nonstatic nested classes. Thus, any class declaration that is inside another class
that does not use the static (keyword) modifier would be termed an inner class in Java.
There are three types of inner classes in Java: member class, local class, and anonym-
ous class. In this section, you will discover what the differences are between these in-
ner classes, as well as how they are implemented .
Like nested classes, member classes are defined within the body of the containing
(parent) class. You can declare a member class anywhere within the body of the con-
taining class. You would declare a member class if you wanted to access data fields
(variables or constants) and methods belonging to the containing class without having
to provide a path (via dot notation) to the data field or method
( ClassName.DataField or ClassName.Method ). A member class can be
thought of as a nested class that does not use the Java static modifier keyword.
Whereas a nested class is referenced through its containing, or top-level, class, us-
ing a dot notation path to the static nested class, a member class, because it is not static,
Search WWH ::




Custom Search