You are on page 1of 20

Object Oriented Concepts

Prajakta
Class:
User defined blueprint.

Object :
Basic runtime entity.
Object oriented Concepts:

Inheritance

Encapsulation

Abstraction

Polymorphism
Inheritance :

one class acquires the properties (methods


and fields) of another.
Single Inheritance Multilevel Inheritance
Single Inheritance :
Derived class can inherit properties and behavior from
single parent class.

Multilevel Inheritance :
class can also be derived from one class, which is
already derived from another class.
Class A :
pass

Class B :
pass

Class C (A,B):
Multiple Inheritance :

class can inherit features from multiple base


classes using multiple inheritance.

Hierarchical Inheritance:

When several classes are derived from


common base class it is called hierarchical
inheritance.
class Base: class Sub2(Base):
def m1(self): def m3(self): class Sub4(Sub2):
a= 10 a= 10 def m5(self):
b =20 b =20 a= 10
c=a+b c=b*a b =20
print("addition is :",c) print("multiplication is :",c) c=b%a
class Sub1(Base): class Sub3(Sub1): print("Modulas is :",c)
def m2(self): def m4(self): obj1 = Sub4()
a= 10 a= 10 obj1.m3()
b =20 b =20 obj3 =Sub2()
c=b-a c=b/a obj3.m1()
print("subtraction is :",c) print("Division is :",c)
class Base:
def m1(self):
a= 10
b =20
c=a+b
print("addition is :",c)
Polymorphism :
Making more than one forms.

single action in different ways can be


performed.
Encapsulation :

Encapsulation is defined as the wrapping up of


data under a single unit.
Abstraction :
Hiding internal details.

Only method declaration and no method body


present.
Method Overloading :

In a class we can have same method but


different parameters.

Method Overriding :

Declaring a method in sub class which is


already present in parent class is known
as method overriding.

You might also like