0% found this document useful (0 votes)
18 views12 pages

Object Oriented Programming

Object-oriented programming uses three main principles - encapsulation, inheritance, and polymorphism. Encapsulation binds code and data together within a class and protects them from outside interference. Inheritance allows a subclass to inherit the properties and behaviors of its parent superclass. Polymorphism allows the same method to behave differently depending on the object that calls it, so subclasses can define their own implementation of a method.

Uploaded by

Priyanka Desai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views12 pages

Object Oriented Programming

Object-oriented programming uses three main principles - encapsulation, inheritance, and polymorphism. Encapsulation binds code and data together within a class and protects them from outside interference. Inheritance allows a subclass to inherit the properties and behaviors of its parent superclass. Polymorphism allows the same method to behave differently depending on the object that calls it, so subclasses can define their own implementation of a method.

Uploaded by

Priyanka Desai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 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