Professional Documents
Culture Documents
(http://docs.oracle.com/javase/tutorial/java/javaOO/more.
html)
Subclass-
Same
Modifier Class Outside World
Package
package
private Y N N N
No (default) Y Y N N
protected Y Y Y N
public Y Y Y Y
y-=7
1000 x=5
y=6
800 x=4
obj1 1000
obj2 800
N 10 9999
• Constants:
– The static modifier, in combination with
the final modifier, is also used to define
constants. The final modifier indicates
that the value of this field cannot
change.
static final double PI = 3.141592653589793;
14
Nested classes…
A nested class violates the
recommendation “low coupling” in class
design. Why are nested classes used?
• It is a way of logically grouping classes that
are only used in one place.
• It increases encapsulation.
• Nested classes can lead to more readable
and maintainable code.
15
Static Nested Classes Demo…
• Class-level nested
class.
• Because the static
nested object is
stored separately
from enclosing
instances, static
nested object can
be initiated
without enclosing
objects.
A method of nested
class can access all inner: 3000
obj
members of its x =5
enclosing class 2000
obj: 2000
x =5
1000
obj: 1000
in1: 2000
in2: 3000
18
Inner Classes
Defined Inside Methods
19
How Compiler Treats Nested Class?