Section 1 :Declaration
and Access Control
classes, inner 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.
applies to classes and methods.
must be declared abstract
if any of the following conditions is true :
class has any abstract
class inherits any abstract
methods but does not implement them.
class declares that it implements an
interface but does not
implement all of its methods.
way, abstract is the
opposite to final. A
final class cannot be
sub-classed but an abstract
class must be sub-classed. An
abstract class can have non-abstract methods.
applied to a method, it means that it has not been
implemented in its class. Any other class extending
this class must either implement the inherited
abstract method or itself
be declared abstract.
applies to classes, methods and variables.
A variable can be declared as
final. Doing so prevents its contents being
changed. This means a final
variable must be initialized when it is declared. It
is common coding convention to choose all uppercase
identifiers for Ďfinalí
variables. Final variables do not occupy memory on a
per-instance basis. Thus, it is essentially a
constant. If a
final variable is a
reference to an object, it is the reference that must
stay the same, not the object. It means that the
reference cannot be assigned to some other object, but
data of the object can be changed.
final class cannot be
final method cannot be
be applied to variables, methods and initializer
applied to a variable, the variable belongs to the
class itself and not to its objects. All the objects
of the class share the variable. If you modify the
value of a static
variable in one object, the value gets changed for all
the objects of the class since there is only one
variable being shared among all the objects.
static initializer block
is executed when the class is loaded.
declared static have
They can only call other
They must only access
They cannot refer to Ďthisí or Ďsuperí in anyway.
static method cannot be
overridden to be non static.
be applied to methods only.
indicates that the method body is to be found
elsewhere i.e. outside the JVM, in a library. Native
code is written in a non java language and compiled
for a single target machine type.
applies only to variables. A
transient variable is not stored as part of its
objectís persistent state. Many objects, especially
those implementing Serializable or Externalizable
interfaces, can have their states serialized and
written to some destination outside the JVM. This is
done by passing the object to the writeObject() method
of the ObjectOutputStream class. If the stream is
chained to a file output stream, then the objectís
state is written to a file. If the stream is chained
to a socketís output stream then the objectís state is
written to the network. In both cases, the object can
be reconstituted by reading from an object input
will be times when an object will contain extremely
sensitive data. Once an object is written to a
destination outside JVM, none of the Javaís elaborate
security mechanisms is in effect. If you declare a
variable transient, itís
value will not be written out during serialization.
It is applied only to variables. It indicates that
such variables might be modified asynchronously, so
the compiler takes special precautions. Volatile
variables are of interest in multi-processor
method or variable declared
public can be accessed by any other code in a
member can only be accessed by other members of its
member does not have an explicit access specification,
it is visible to subclass as well as to other classes
in the same package.
allows access from everywhere but except for different
Note: You cannot combine some of
these modifiers together. Some of the cases are:
access modifiers can be combined. Such as
methods cannot be abstract,
abstract method cannot
section1-1 | section1-2 | section1-3 | section1-4
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11