Java Reference
In-Depth Information
SR3. The folder looks like the one in Fig. 3.1, except that name has value
"Clinton" and start has value 1996 . The value of the call is the name that you
placed in the tab of the folder.
SR4. A constructor without parameters is not defined in class Circle . Two
arguments are needed within the parentheses.
SR5.
Evaluation creates this folder and yields the name a9 :
a9
Coordinates
Coordinates( int , int )
toString()
x5
y6
SR6. false , false , true , true .
3.3
Static components
As you know, a component (variable or method) that is declared in a class may
have the modifier static . Such a component is called a static component , or
class component . During execution of a program, a static component is in the file
drawer for the class in which it is defined. There is only one copy of the class
component —it does not appear in instances of the class. One references a static
variable v (or method m ) in a class C using C.v (or C.m(…) ).
We now discuss the reasons for making a component static.
Lesson pages
3-1 and 3-2
discuss static
methods. Page
3-2 looks at
class Math.
3.3.1
Static variables
A variable that is declared with modifier static within a class is called a static
variable , or class variable . Such a variable does not appear in each manila fold-
er of the class; instead, there is only one copy of it, and it goes directly into the
class file-drawer. We discuss two uses of class variables.
Constants
A constant is a variable that is declared with modifier final . Such a decla-
ration must be an initializing declaration, and no other assignments to it are
allowed. The variable cannot be changed. An example is variable MAX_VALUE in
class Integer :
Style Note
13.1, 13.1.1
naming
constants
public static final int MAX_VALUE= 2147483647;
The purpose of such a constant is to provide a mnemonic name for a value, mak-
ing it easier for programmers to reference a value. Another example is the con-
stant Math.PI (i.e. the constant PI in class Math ), which is the closest double
Search WWH ::




Custom Search