Java Reference
In-Depth Information
2.1.1. Class Members
A class can have three kinds of members:
•
Fields
are the data variables associated with a class and its ob-
jects and hold the state of the class or object.
•
Methods
contain the executable code of a class and define the be-
havior of objects.
•
Nested classes
and
nested interfaces
are declarations of classes
or interfaces that occur nested within the declaration of another
class or interface.
In this chapter we concentrate on the basic members: fields and meth-
2.1.2. Class Modifiers
A class declaration can be preceded by class
modifiers
that give the class
certain properties:
•
annotations
Annotations and annotation types are discussed in
•
public
A
public
class is publicly accessible: Anyone can declare
references to objects of the class or access its public members.
Without a modifier a class is only accessible within its own
pack-
age.
You'll learn about general access control in
Section 2.3
on
members are discussed in
Chapter 18
.
•
abstract
An
abstract
class is considered incomplete and no in-
stances of the class may be created. Usually this is because the
class contains
abstract
methods that must be implemented by a
subclass. You'll learn about this in "
Abstract Classes and Meth-