Game Development Reference
In-Depth Information
}
}
You can also declare an inner class protected , meaning that it can only be accessed
by any subclasses of the parent class. If you declare a class inside a lower-level Java
programming structure that is not a class, such as a method or an iteration control
structure (commonly called a loop), it would technically be referred to as a local class .
A local class is only visible inside that block of code; thus, it does not allow (or make
sense to use) class modifiers, such as static, public, protected, or private. A local class
is used like a local variable , except that it is a complex Java coding construct rather
than a simple a data field value that is used locally.
Finally, there is a type of inner class called an anonymous class . An anonymous
class is a local class that has not been given a class name. You are likely to encounter
anonymous classes far more often than you are local classes. This is because program-
mers often do not name their local classes (making them anonymous classes); the logic
local classes contain is only used locally , to their declaration, and so these classes do
not really need to have a name—they are only referenced internally to that block of
Java code.
Java Methods: Core Java Function Code
Constructs
Inside classes, you generally have methods and the data fields (variables or constants)
that these methods use. Because we are going from outside to inside, or top-level struc-
tures to lower-level structures, I will cover methods next. Methods are sometimes
called functions in other programming languages. Figure 3-2 provides an example of
the .start() method, showing how the method holds the programming logic that creates
a basic “Hello World!” application. The programming logic inside the method uses
Java programming statements to create a Stage object and a Scene object, place a but-
ton on the screen in a StackPane object, and define event - handling logic, such that
when the button is clicked, the bootstrap Java code writes the “Hello World!” text to
your NetBeans IDE output area.
The method declaration starts with an access modifier keyword, either public, pro-
tected, private, or package private (which is designated by not using any access control
modifier at all). As you can see in the figure, the .start() method has been declared, us-
ing the public access control modifier.
Search WWH ::




Custom Search