SlideShare a Scribd company logo
1 of 29
Inheritance
Polymorphism
Overloading
Overriding
What is Inheritance?
Inheritance is a powerful feature in object oriented
programming.
It is the capability of one class to derive or inherit the
properties from some another class.
Every Car is a vehicles. To show this relationship, we take an example.
Vehicles
Car
In this representation, we use an arrow towards the base class as a UML
(Unified Modeling Language) convention.
Vehicles can be called any of the following:
 Super Class
 Parent Class
 Base Class
And car is:
 Sub Class
 Child Class
 Derived Class
Inheritance Syntax
>>> class Person:
pass
>>> class Car(Vehicles):
pass
>>> issubclass(Car,Vehicles)
Here, class Car inherits from class Vehicles. We use the function
issubclass() to confirm that car is a subclass of person.
Types of Inheritance
Single
Inheritance
Multilevel
Inheritance
Multiple
Inheritance
Hierarchical
Inheritance
Hybrid
Inheritance
Single Inheritance
Child class inherits from only one parent class
Example:
class Animal:
def speak(self):
print("Animal Speaking")
#child class Lion inherits the base class Animal
class Lion(Animal):
def roar(self):
print(“Lion roaring")
d = Lion()
d.roar()
d.speak()
Lion roaring
Animal Speaking
Output:
Multiple inheritance
Inherit multiple base classes in the child class
Class 1 Class 2
Class N
Class 3
Example:
class Calculation1:
def Addition(self,x,y):
return x+y;
class Calculation2:
def Multiplication(self,x,y):
return a*b;
class Derived(Calculation1,Calculation2):
def Division(self,a,b):
return a/b;
d = Derived()
print(d.Addition(2,4))
print(d.Multiplication(2,4))
print(d.Division(2,4))
Output:
6
8
0.5
Multi-Level inheritance
Class 2
Class N
In Multi-level inheritance derived class inherits from another
derived class. There is no limit for level.
Class 1
Example:
class Animal:
def speak(self):
print("Animal Speaking")
#The child class Lion inherits the base class Animal
class Lion(Animal):
def roar(self):
print(“Lion roaring")
#The child class BabyLion inherits another child class Lion
class BabyLion(Lion):
def eat(self):
print("Eating meat...")
d = BabyLion()
d.roar()
d.speak()
d.eat()
Output:
Lion roaring
Animal Speaking
Eating meat...
Hierarchical inheritance
In hierarchical inheritance more than one derived classes are created from
a single base class.
Class 3
Class 2
Base Class
Class 1
Hybrid inheritance
Class 3
Class 4
Hybrid inheritance is a combination of multiple inheritance
and multilevel inheritance.
Class 1
Class 2
Polymorphism
 Polymorphism means many forms or multiple form.
In programming polymorphism means the same name
of function (but different parameters) that is used for
different types.
 Polymorphism simply means that we can call the
same method name with different parameters, and
depending on the parameters, it will do different
things.
Example:
len(“GKTCS")
len([5,2,8,4,45,75,3,92,33])
# returns 5 as result
# returns 9 as result
In this case the function len() taking string as input in the first case and is
taking list as input in the second case.
Overloading
Method
Overloading
Operator
Overloading
Overloading is the ability of a function or operator to behave differently dependin
g on the parameters passed on to the function or the operands on which the oper
ator operates.
Overloading
Method OR Function Overloading
Method overloading or function
overloading is a type of polymorphism in
which we can define a number of methods
with the same name but with a different
number of parameters as well as
parameters can be of different types.
Example:
# Takes two argument and print their Addition
def addition(a, b):
x = a + b
print(x)
# Takes three argument and print their Addition
def addition(a, b, c):
x = a + b + c
print(x)
# below line shows an error
#addition(7, 2)
# This line will call the second product method
addition(2, 5, 1)
Output:
 In the above code we have defined two addition method, but we can only
use the second addition method, as python does not supports method
overloading.
 We may define many method of same name and different argument but
we can only use the latest defined method. Calling the other method will
produce an error. Like here calling addition(7,2) will produce an error as
the latest defined addition method takes three arguments.
08
Operator Overloading
We can use ’+’ operator for adding numbers and at the
same time to concatenate strings. It is possible
because ’+’ operator is overloaded by both int class
and str class.
Example:
# Addition of two numbers
print(3 + 2)
# Concatenate two strings
print("GKTCS“ + “Innovations“)
# Product of two numbers
print(3 * 2)
# Repeat the String
print("GKTCS"*3)
Output:
5
GKTCS Innovations
6
GKTCSGKTCSGKTCS
Overriding
Override means having two methods with
the same name but doing different tasks.
It means that one of the methods
overrides the other.
The concept of Method overriding allows
us to change or override the Parent Class
function in the Child Class.
In Python, to override a method, you have to meet certain
conditions
 You can’t override a method within the same class. It means you
have to do it in the child class using the Inheritance concept.
 To override the Parent Class method, you have to create a method
in the Child class with the same name and the same number of
parameters.
Example:
# Python Method Overriding
class Employee:
def message(self):
print('This message is from Employee Class')
class Company(Employee):
def message(self):
print('This Company class is inherited from Employee’)
emp = Employee()
emp.message()
comp = Company()
comp.message()
Output:
'This message is from Employee Class'
'This Company class is inherited from Employee'

More Related Content

Similar to Inheritance_Polymorphism_Overloading_overriding.pptx

Inheritance in Java beginner to advance with examples.pptx
Inheritance in Java beginner to advance with examples.pptxInheritance in Java beginner to advance with examples.pptx
Inheritance in Java beginner to advance with examples.pptxnaeemcse
 
Polymorphism in java
Polymorphism in javaPolymorphism in java
Polymorphism in javasureshraj43
 
An Introduction to C# and .NET Framework (Basic)
An Introduction to C# and .NET Framework (Basic)An Introduction to C# and .NET Framework (Basic)
An Introduction to C# and .NET Framework (Basic)Khubaib Ahmad Kunjahi
 
Function overloading
Function overloadingFunction overloading
Function overloadingzindadili
 
Application package
Application packageApplication package
Application packageJAYAARC
 
polymorphism.pdf
polymorphism.pdfpolymorphism.pdf
polymorphism.pdfriyawagh2
 
C++ programming introduction
C++ programming introductionC++ programming introduction
C++ programming introductionsandeep54552
 
Polymorphism & Templates
Polymorphism & TemplatesPolymorphism & Templates
Polymorphism & TemplatesMeghaj Mallick
 
Learn java lessons_online
Learn java lessons_onlineLearn java lessons_online
Learn java lessons_onlinenishajj
 
Object Oriented Principles
Object Oriented PrinciplesObject Oriented Principles
Object Oriented PrinciplesSujit Majety
 
Question and answer Programming
Question and answer ProgrammingQuestion and answer Programming
Question and answer ProgrammingInocentshuja Ahmad
 
Learn C# Programming Polymorphism & Operator Overloading
Learn C# Programming Polymorphism & Operator OverloadingLearn C# Programming Polymorphism & Operator Overloading
Learn C# Programming Polymorphism & Operator OverloadingEng Teong Cheah
 
Java OOPS Concept
Java OOPS ConceptJava OOPS Concept
Java OOPS ConceptRicha Gupta
 
Function overloading and overriding
Function overloading and overridingFunction overloading and overriding
Function overloading and overridingRajab Ali
 
1669958779195.pdf
1669958779195.pdf1669958779195.pdf
1669958779195.pdfvenud11
 

Similar to Inheritance_Polymorphism_Overloading_overriding.pptx (20)

Inheritance in Java beginner to advance with examples.pptx
Inheritance in Java beginner to advance with examples.pptxInheritance in Java beginner to advance with examples.pptx
Inheritance in Java beginner to advance with examples.pptx
 
Polymorphism in java
Polymorphism in javaPolymorphism in java
Polymorphism in java
 
An Introduction to C# and .NET Framework (Basic)
An Introduction to C# and .NET Framework (Basic)An Introduction to C# and .NET Framework (Basic)
An Introduction to C# and .NET Framework (Basic)
 
Function overloading
Function overloadingFunction overloading
Function overloading
 
JAVA-PPT'S.pdf
JAVA-PPT'S.pdfJAVA-PPT'S.pdf
JAVA-PPT'S.pdf
 
Application package
Application packageApplication package
Application package
 
Basics of oops concept
Basics of oops conceptBasics of oops concept
Basics of oops concept
 
polymorphism.pdf
polymorphism.pdfpolymorphism.pdf
polymorphism.pdf
 
C++ programming introduction
C++ programming introductionC++ programming introduction
C++ programming introduction
 
Polymorphism & Templates
Polymorphism & TemplatesPolymorphism & Templates
Polymorphism & Templates
 
E3
E3E3
E3
 
Delphi qa
Delphi qaDelphi qa
Delphi qa
 
Learn java lessons_online
Learn java lessons_onlineLearn java lessons_online
Learn java lessons_online
 
Object Oriented Principles
Object Oriented PrinciplesObject Oriented Principles
Object Oriented Principles
 
Question and answer Programming
Question and answer ProgrammingQuestion and answer Programming
Question and answer Programming
 
C# interview
C# interviewC# interview
C# interview
 
Learn C# Programming Polymorphism & Operator Overloading
Learn C# Programming Polymorphism & Operator OverloadingLearn C# Programming Polymorphism & Operator Overloading
Learn C# Programming Polymorphism & Operator Overloading
 
Java OOPS Concept
Java OOPS ConceptJava OOPS Concept
Java OOPS Concept
 
Function overloading and overriding
Function overloading and overridingFunction overloading and overriding
Function overloading and overriding
 
1669958779195.pdf
1669958779195.pdf1669958779195.pdf
1669958779195.pdf
 

More from MalligaarjunanN

English article power point presentation eng.pptx
English article power point presentation eng.pptxEnglish article power point presentation eng.pptx
English article power point presentation eng.pptxMalligaarjunanN
 
Digital principle and computer design Presentation (1).pptx
Digital principle and computer design Presentation (1).pptxDigital principle and computer design Presentation (1).pptx
Digital principle and computer design Presentation (1).pptxMalligaarjunanN
 
Technical English grammar and tenses.pptx
Technical English grammar and tenses.pptxTechnical English grammar and tenses.pptx
Technical English grammar and tenses.pptxMalligaarjunanN
 
Polymorphism topic power point presentation li.pptx
Polymorphism topic power point presentation li.pptxPolymorphism topic power point presentation li.pptx
Polymorphism topic power point presentation li.pptxMalligaarjunanN
 
Chemistry iconic bond topic chem ppt.pptx
Chemistry iconic bond topic chem ppt.pptxChemistry iconic bond topic chem ppt.pptx
Chemistry iconic bond topic chem ppt.pptxMalligaarjunanN
 
C programming DOC-20230723-WA0001..pptx
C programming  DOC-20230723-WA0001..pptxC programming  DOC-20230723-WA0001..pptx
C programming DOC-20230723-WA0001..pptxMalligaarjunanN
 
Chemistry fluorescent topic chemistry.pptx
Chemistry fluorescent topic  chemistry.pptxChemistry fluorescent topic  chemistry.pptx
Chemistry fluorescent topic chemistry.pptxMalligaarjunanN
 
C programming power point presentation c ppt.pptx
C programming power point presentation c ppt.pptxC programming power point presentation c ppt.pptx
C programming power point presentation c ppt.pptxMalligaarjunanN
 
Python programming file handling mhhk.pptx
Python programming file handling mhhk.pptxPython programming file handling mhhk.pptx
Python programming file handling mhhk.pptxMalligaarjunanN
 
Computer organisation and architecture updated unit 2 COA ppt.pptx
Computer organisation and architecture updated unit 2 COA ppt.pptxComputer organisation and architecture updated unit 2 COA ppt.pptx
Computer organisation and architecture updated unit 2 COA ppt.pptxMalligaarjunanN
 
Data structures trees and graphs - Heap Tree.pptx
Data structures trees and graphs - Heap Tree.pptxData structures trees and graphs - Heap Tree.pptx
Data structures trees and graphs - Heap Tree.pptxMalligaarjunanN
 
Data structures trees and graphs - AVL tree.pptx
Data structures trees and graphs - AVL  tree.pptxData structures trees and graphs - AVL  tree.pptx
Data structures trees and graphs - AVL tree.pptxMalligaarjunanN
 
Data structures trees - B Tree & B+Tree.pptx
Data structures trees - B Tree & B+Tree.pptxData structures trees - B Tree & B+Tree.pptx
Data structures trees - B Tree & B+Tree.pptxMalligaarjunanN
 
Computer organisation and architecture .
Computer organisation and architecture .Computer organisation and architecture .
Computer organisation and architecture .MalligaarjunanN
 
Python programming variables and comment
Python programming variables and commentPython programming variables and comment
Python programming variables and commentMalligaarjunanN
 
pythoncommentsandvariables-231016105804-9a780b91 (1).pptx
pythoncommentsandvariables-231016105804-9a780b91 (1).pptxpythoncommentsandvariables-231016105804-9a780b91 (1).pptx
pythoncommentsandvariables-231016105804-9a780b91 (1).pptxMalligaarjunanN
 
Python programming - Functions and list and tuples
Python programming - Functions and list and tuplesPython programming - Functions and list and tuples
Python programming - Functions and list and tuplesMalligaarjunanN
 
presentation-130909130658- (1).pdf
presentation-130909130658- (1).pdfpresentation-130909130658- (1).pdf
presentation-130909130658- (1).pdfMalligaarjunanN
 

More from MalligaarjunanN (20)

English article power point presentation eng.pptx
English article power point presentation eng.pptxEnglish article power point presentation eng.pptx
English article power point presentation eng.pptx
 
Digital principle and computer design Presentation (1).pptx
Digital principle and computer design Presentation (1).pptxDigital principle and computer design Presentation (1).pptx
Digital principle and computer design Presentation (1).pptx
 
Technical English grammar and tenses.pptx
Technical English grammar and tenses.pptxTechnical English grammar and tenses.pptx
Technical English grammar and tenses.pptx
 
Polymorphism topic power point presentation li.pptx
Polymorphism topic power point presentation li.pptxPolymorphism topic power point presentation li.pptx
Polymorphism topic power point presentation li.pptx
 
Chemistry iconic bond topic chem ppt.pptx
Chemistry iconic bond topic chem ppt.pptxChemistry iconic bond topic chem ppt.pptx
Chemistry iconic bond topic chem ppt.pptx
 
C programming DOC-20230723-WA0001..pptx
C programming  DOC-20230723-WA0001..pptxC programming  DOC-20230723-WA0001..pptx
C programming DOC-20230723-WA0001..pptx
 
Chemistry fluorescent topic chemistry.pptx
Chemistry fluorescent topic  chemistry.pptxChemistry fluorescent topic  chemistry.pptx
Chemistry fluorescent topic chemistry.pptx
 
C programming power point presentation c ppt.pptx
C programming power point presentation c ppt.pptxC programming power point presentation c ppt.pptx
C programming power point presentation c ppt.pptx
 
Python programming file handling mhhk.pptx
Python programming file handling mhhk.pptxPython programming file handling mhhk.pptx
Python programming file handling mhhk.pptx
 
Computer organisation and architecture updated unit 2 COA ppt.pptx
Computer organisation and architecture updated unit 2 COA ppt.pptxComputer organisation and architecture updated unit 2 COA ppt.pptx
Computer organisation and architecture updated unit 2 COA ppt.pptx
 
Data structures trees and graphs - Heap Tree.pptx
Data structures trees and graphs - Heap Tree.pptxData structures trees and graphs - Heap Tree.pptx
Data structures trees and graphs - Heap Tree.pptx
 
Data structures trees and graphs - AVL tree.pptx
Data structures trees and graphs - AVL  tree.pptxData structures trees and graphs - AVL  tree.pptx
Data structures trees and graphs - AVL tree.pptx
 
Data structures trees - B Tree & B+Tree.pptx
Data structures trees - B Tree & B+Tree.pptxData structures trees - B Tree & B+Tree.pptx
Data structures trees - B Tree & B+Tree.pptx
 
Computer organisation and architecture .
Computer organisation and architecture .Computer organisation and architecture .
Computer organisation and architecture .
 
Python programming variables and comment
Python programming variables and commentPython programming variables and comment
Python programming variables and comment
 
pythoncommentsandvariables-231016105804-9a780b91 (1).pptx
pythoncommentsandvariables-231016105804-9a780b91 (1).pptxpythoncommentsandvariables-231016105804-9a780b91 (1).pptx
pythoncommentsandvariables-231016105804-9a780b91 (1).pptx
 
Python programming - Functions and list and tuples
Python programming - Functions and list and tuplesPython programming - Functions and list and tuples
Python programming - Functions and list and tuples
 
X02PredCalculus.ppt
X02PredCalculus.pptX02PredCalculus.ppt
X02PredCalculus.ppt
 
presentation-130909130658- (1).pdf
presentation-130909130658- (1).pdfpresentation-130909130658- (1).pdf
presentation-130909130658- (1).pdf
 
Presentation (5)-1.pptx
Presentation (5)-1.pptxPresentation (5)-1.pptx
Presentation (5)-1.pptx
 

Recently uploaded

Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxhumanexperienceaaa
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSISrknatarajan
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)Suman Mia
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...RajaP95
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSRajkumarAkumalla
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 

Recently uploaded (20)

Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 

Inheritance_Polymorphism_Overloading_overriding.pptx

  • 2. What is Inheritance? Inheritance is a powerful feature in object oriented programming. It is the capability of one class to derive or inherit the properties from some another class.
  • 3. Every Car is a vehicles. To show this relationship, we take an example. Vehicles Car In this representation, we use an arrow towards the base class as a UML (Unified Modeling Language) convention.
  • 4. Vehicles can be called any of the following:  Super Class  Parent Class  Base Class And car is:  Sub Class  Child Class  Derived Class
  • 5. Inheritance Syntax >>> class Person: pass >>> class Car(Vehicles): pass >>> issubclass(Car,Vehicles) Here, class Car inherits from class Vehicles. We use the function issubclass() to confirm that car is a subclass of person.
  • 7. Single Inheritance Child class inherits from only one parent class Example: class Animal: def speak(self): print("Animal Speaking") #child class Lion inherits the base class Animal class Lion(Animal): def roar(self): print(“Lion roaring") d = Lion() d.roar() d.speak()
  • 9. Multiple inheritance Inherit multiple base classes in the child class Class 1 Class 2 Class N Class 3
  • 10. Example: class Calculation1: def Addition(self,x,y): return x+y; class Calculation2: def Multiplication(self,x,y): return a*b; class Derived(Calculation1,Calculation2): def Division(self,a,b): return a/b; d = Derived() print(d.Addition(2,4)) print(d.Multiplication(2,4)) print(d.Division(2,4))
  • 12. Multi-Level inheritance Class 2 Class N In Multi-level inheritance derived class inherits from another derived class. There is no limit for level. Class 1
  • 13. Example: class Animal: def speak(self): print("Animal Speaking") #The child class Lion inherits the base class Animal class Lion(Animal): def roar(self): print(“Lion roaring") #The child class BabyLion inherits another child class Lion class BabyLion(Lion): def eat(self): print("Eating meat...") d = BabyLion() d.roar() d.speak() d.eat()
  • 15. Hierarchical inheritance In hierarchical inheritance more than one derived classes are created from a single base class. Class 3 Class 2 Base Class Class 1
  • 16. Hybrid inheritance Class 3 Class 4 Hybrid inheritance is a combination of multiple inheritance and multilevel inheritance. Class 1 Class 2
  • 17. Polymorphism  Polymorphism means many forms or multiple form. In programming polymorphism means the same name of function (but different parameters) that is used for different types.  Polymorphism simply means that we can call the same method name with different parameters, and depending on the parameters, it will do different things.
  • 18. Example: len(“GKTCS") len([5,2,8,4,45,75,3,92,33]) # returns 5 as result # returns 9 as result In this case the function len() taking string as input in the first case and is taking list as input in the second case.
  • 19. Overloading Method Overloading Operator Overloading Overloading is the ability of a function or operator to behave differently dependin g on the parameters passed on to the function or the operands on which the oper ator operates. Overloading
  • 20. Method OR Function Overloading Method overloading or function overloading is a type of polymorphism in which we can define a number of methods with the same name but with a different number of parameters as well as parameters can be of different types.
  • 21. Example: # Takes two argument and print their Addition def addition(a, b): x = a + b print(x) # Takes three argument and print their Addition def addition(a, b, c): x = a + b + c print(x) # below line shows an error #addition(7, 2) # This line will call the second product method addition(2, 5, 1)
  • 22. Output:  In the above code we have defined two addition method, but we can only use the second addition method, as python does not supports method overloading.  We may define many method of same name and different argument but we can only use the latest defined method. Calling the other method will produce an error. Like here calling addition(7,2) will produce an error as the latest defined addition method takes three arguments. 08
  • 23. Operator Overloading We can use ’+’ operator for adding numbers and at the same time to concatenate strings. It is possible because ’+’ operator is overloaded by both int class and str class.
  • 24. Example: # Addition of two numbers print(3 + 2) # Concatenate two strings print("GKTCS“ + “Innovations“) # Product of two numbers print(3 * 2) # Repeat the String print("GKTCS"*3)
  • 26. Overriding Override means having two methods with the same name but doing different tasks. It means that one of the methods overrides the other. The concept of Method overriding allows us to change or override the Parent Class function in the Child Class.
  • 27. In Python, to override a method, you have to meet certain conditions  You can’t override a method within the same class. It means you have to do it in the child class using the Inheritance concept.  To override the Parent Class method, you have to create a method in the Child class with the same name and the same number of parameters.
  • 28. Example: # Python Method Overriding class Employee: def message(self): print('This message is from Employee Class') class Company(Employee): def message(self): print('This Company class is inherited from Employee’) emp = Employee() emp.message() comp = Company() comp.message()
  • 29. Output: 'This message is from Employee Class' 'This Company class is inherited from Employee'