C
e
r
t
P
r
s
8
(
S
U
N
)
/
S
u
n
C
e
r
t
i
f
i
e
d
P
r
o
g
r
a
m
m
e
r
&
D
e
v
e
l
o
p
e
r
f
o
r
J
a
v
a
2
S
t
u
d
y
G
u
i
d
e
/
S
i
e
r
r
a
/
2
2
2
6
8
4
-
6
/
C
h
a
p
t
e
r
2
B
l
i
n
d
F
o
l
i
o
2
:
5
9
2
Declarations and
Access Control
CERTIFICATION OBJECTIVES
•
Declarations and Modifiers
•
Declaration Rules
•
Interface Implementation
✓
Two-Minute Drill
Q&A
Self Test
P:\010Comp\CertPrs8\684-6\ch02.vp
Friday, November 15, 2002 11:20:28 AM
C
o
l
o
r
p
r
o
f
i
l
e
:
G
e
n
e
r
i
c
C
M
Y
K
p
r
i
n
t
e
r
p
r
o
f
i
l
e
C
o
m
p
o
s
i
t
e
D
e
f
a
u
l
t
s
c
r
e
e
n
We’re on a roll. We’ve covered the fundamentals of keywords, primitives, arrays,
and variables. Now it’s time to drill deeper into rules for declaring classes,
methods, and variables. We’ll tackle access modifiers, abstract method
implementation, interface implementation, and what you can and can’t return from a method.
Chapter 2 includes the topics asked most often on the exam, so you really need a solid grasp
of this chapter’s content. Grab your caffeine and let’s get started.
CERTIFICATION OBJECTIVE
Declarations and Modifiers (Exam Objective 1.2)
Declare classes, nested classes, methods, instance variables, static variables, and automatic
(method local) variables making appropriate use of all permitted modifiers (such as
public, final, static, abstract, and so forth). State the significance of
each of these modifiers both singly and in combination, and state the effect of package
relationships on declared items qualified by these modifiers.
When you write code in Java, you’re writing classes. Within those classes, as
you know, are variables and methods (plus a few other things). How you declare
your classes, methods, and variables dramatically affects your code’s behavior. For
example, a public method can be accessed from code running anywhere in your
application. Mark that method private, though, and it vanishes from everyone’s
radar (except the class in which it was declared). For this objective, we’ll s