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

Application package
Application packageApplication package
Application package
JAYAARC
 

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

More from MalligaarjunanN (20)

bro_nodejs-1 front end development .pdf
bro_nodejs-1 front end development  .pdfbro_nodejs-1 front end development  .pdf
bro_nodejs-1 front end development .pdf
 
Microprocessor and microcontroller record.pdf
Microprocessor and microcontroller record.pdfMicroprocessor and microcontroller record.pdf
Microprocessor and microcontroller record.pdf
 
8087 MICROPROCESSOR and diagram with definition.pdf
8087 MICROPROCESSOR and diagram with definition.pdf8087 MICROPROCESSOR and diagram with definition.pdf
8087 MICROPROCESSOR and diagram with definition.pdf
 
8089 microprocessor with diagram and analytical
8089 microprocessor with diagram and analytical8089 microprocessor with diagram and analytical
8089 microprocessor with diagram and analytical
 
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
 

Recently uploaded

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
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ssuser89054b
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Recently uploaded (20)

data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
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, ...
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdf
 
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLPVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
 
Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
 

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'