Access Modifiers & Keywords: SZABIST Islamabad
Access Modifiers & Keywords: SZABIST Islamabad
SZABIST
Islamabad
Agenda
• Acess
Modifers
and
their
use
• Friendly
Access
• Modifiers
explained
• Rules
for
Overriding
• The
Final
Modifier
• The
Abstract
Modifier
• The
NaFve
Modifier
• The
Transient
Modifier
• The
Synchronized
Modifier
• The
VolaFle
Modifier
Access
Modifiers
• public
– Can
be
used
in
any
Java
program
without
restricFon
• private
– may
only
be
used
by
the
instance
of
the
class
that
declares
the
variable
or
method
• protected
– only
variables,
methods,
and
inner
classes
can
be
declared
protected
– available
to
all
classes
in
the
same
package
– available
to
all
subclasses(
even
those
in
different
packages
)
Overriding
Methods
friendly
Protected
public
Final
Modifier
class Tester {
final Walrus w1 = new Walrus(1500);
void test() {
w1 = new Walrus(1400); // Illegal
w1.weight = 1800; // Legal
}
}
Abstract
Modifier