You are on page 1of 12

Object

Oriented

Encapsulation
Inheritance
Polymorphism

Three Principles

Encapsulation is the mechanism that binds


together code and the data it
manipulates, and keep them both safe
from outside interference and misuse.

Public instance
variable
Public method
Private instance
variable
Private method

In

java, the basis of encapsulation is the


class.

class defines the structure & behaviour


(data and code) that will be shared by a
set of objects.

Thus,

a class is a logical construct; an


object has physical reality.

public class Test {


private int x;
public Test() {
}
public Test(int x) {
this.x = x;

Labrador inherits the encapsulation of all its Super classes

nderstand
u
l
il
w
u
o
y
,
ple
s have a
m
t
c
a
x
je
e
b
o
is
h
ll
t
a
,
m
e
r
Hope fro
this pictu
In
.
ntation.
is
e
m
m
s
le
i
p
h
p
im
r
t
o
n
m
e
w hat Poly
as a differ
action for a
h
n
h
a
c
e
a
r
e
la
t
c
u
e
b
d
ak()
, you can
is
th
o
d
method Spe
to
n w rite
u
a
o
c
y
u
s
o
y
w
,
o
s
ll
s
a
la
m
each subc
r
fo
Polymorphis
t
u
b
s
e
s
subclas
class and its
ant later.
w
u
o
y
t
a
h
w
exactly

abstract class LivingBeing { abstract public void speak(); }


class Boy extends LivingBeing
{
public void speak()
{
System.out.println(Hello);
}
}
class Puppy extends LeavingBeing

You might also like