Start of Tutorial > Start of Trail > Start of Lesson |
Search
Feedback Form |
A class definition has two parts: a class declaration and a class body. For details about the elements of a class declaration, refer to the table in the section Controlling Access to Members of a Class. The class body contains member variables, methods, and constructors for the class. A class uses member variables to contain state and uses methods to implement behavior. The table in Declaring Classes lists the possible elements of a member variable declaration and the table in the section Declaring Member Variables lists the possible elements of a method declaration. Constructors initialize a new instance of a class and have the same name as the class.You control access to member variables and methods in the same way: by using an access specifier, such as
private
orpublic
, in the member's declaration. The table in section Defining Methods lists the access specifiers and the effect of each specifier.You specify a class member variable or a class method by using the
static
keyword in the member's declaration. A member that is not declared asstatic
is implicitly an instance member. Class variables are shared by all instance of a class and can be accessed through the class name. Instances of a class get their own copy of each instance variable, which must be accessed through an instance reference.
Start of Tutorial > Start of Trail > Start of Lesson |
Search
Feedback Form |
Copyright 1995-2005 Sun Microsystems, Inc. All rights reserved.