e’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.
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
, 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).
your classes, methods, and variables dramatically affects your code’s behavior. For
method can be accessed from code running anywhere in your
application. Mark that method
, though, and it vanishes from everyone’s
radar (except the class in which it was declared). For this objective, we’ll study the
ways in which you can modify (or not) a class, method, or variable declaration.
You’ll find that we cover modifiers in an extreme level of detail, and though we
know you’re already familiar with them, we’re starting from the very beginning.
Most Java programmers
they know how all the modifiers work, but on closer
study often find out that they don’t (at least not to the degree needed for the exam).
Subtle distinctions are everywhere, so you need to be absolutely certain you’re
solid on everything in this objective before taking the exam.
Declarations and Access Control