Java Reference
In-Depth Information
TOPIC CONCEPT
Class Definitions A class definition specifies the variables and methods that are members of the class.
Class Files Each class must be saved in a file with the same name as the class, and with the extension .java .
Class Variables Class variables are declared using the keyword static , and one instance of each class variable is
shared among all objects of a class.
Instance Variables Each object of a class has its own instance variables — these are variables declared in the class
without using the keyword static.
Static Methods Methods that are specified as static can be called even if no class objects exist, but a static
method cannot refer to instance variables.
Non-Static Methods Methods that are not specified as static can access any of the variables in the class directly.
Recursive Methods Recursive methods are methods that call themselves.
Class Member Ac-
cess
Access to members of a class is determined by the access attributes that are specified for each of
them. These can be public , private , protected , or nothing at all.
Packages Classes can be grouped into a package. If a class in a package is to be accessible from outside the
package, the class must be declared using the keyword public .
Package Members To designate that a class is a member of a package, you use a package statement at the beginning
of the file containing the class definition.
Using a Package
Member
To add classes from a package to a file, you use an import statement immediately following any
package statement in the file.
Nested Classes
A nested class is a class that is defined within the definition of another class. Objects of a nested
class type can be created only in the context of an object of the outer class type.
Creating Static Nes-
ted Class Objects
Objects of a static nested class type can be created independently, but the static nested class name
must be qualified by the outer class name.
Search WWH ::




Custom Search