SlideShare a Scribd company logo
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'
Ad

More Related Content

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
naeemcse
 
Polymorphism in java
Polymorphism in javaPolymorphism in java
Polymorphism in java
sureshraj43
 
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
 
Polymorphism in OPP, JAVA, Method overload.pptx
Polymorphism in OPP, JAVA, Method overload.pptxPolymorphism in OPP, JAVA, Method overload.pptx
Polymorphism in OPP, JAVA, Method overload.pptx
AsifMehmood240435
 
PolyInterfaces.pptnowand tomoroooooooooo
PolyInterfaces.pptnowand tomorooooooooooPolyInterfaces.pptnowand tomoroooooooooo
PolyInterfaces.pptnowand tomoroooooooooo
mugabecharles
 
Function overloading
Function overloadingFunction overloading
Function overloading
zindadili
 
JAVA-PPT'S.pdf
JAVA-PPT'S.pdfJAVA-PPT'S.pdf
JAVA-PPT'S.pdf
AnmolVerma363503
 
Application package
Application packageApplication package
Application package
JAYAARC
 
Basics of oops concept
Basics of oops conceptBasics of oops concept
Basics of oops concept
DINESH KUMAR ARIVARASAN
 
polymorphism.pdf
polymorphism.pdfpolymorphism.pdf
polymorphism.pdf
riyawagh2
 
C++ programming introduction
C++ programming introductionC++ programming introduction
C++ programming introduction
sandeep54552
 
Polymorphism & Templates
Polymorphism & TemplatesPolymorphism & Templates
Polymorphism & Templates
Meghaj Mallick
 
E3
E3E3
E3
lksoo
 
Delphi qa
Delphi qaDelphi qa
Delphi qa
sandy14234
 
Learn java lessons_online
Learn java lessons_onlineLearn java lessons_online
Learn java lessons_online
nishajj
 
Object Oriented Principles
Object Oriented PrinciplesObject Oriented Principles
Object Oriented Principles
Sujit Majety
 
Question and answer Programming
Question and answer ProgrammingQuestion and answer Programming
Question and answer Programming
Inocentshuja Ahmad
 
C# interview
C# interviewC# interview
C# interview
Thomson Reuters
 
Learn C# Programming Polymorphism & Operator Overloading
Learn C# Programming Polymorphism & Operator OverloadingLearn C# Programming Polymorphism & Operator Overloading
Learn C# Programming Polymorphism & Operator Overloading
Eng Teong Cheah
 
Java OOPS Concept
Java OOPS ConceptJava OOPS Concept
Java OOPS Concept
Richa Gupta
 
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
naeemcse
 
Polymorphism in java
Polymorphism in javaPolymorphism in java
Polymorphism in java
sureshraj43
 
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
 
Polymorphism in OPP, JAVA, Method overload.pptx
Polymorphism in OPP, JAVA, Method overload.pptxPolymorphism in OPP, JAVA, Method overload.pptx
Polymorphism in OPP, JAVA, Method overload.pptx
AsifMehmood240435
 
PolyInterfaces.pptnowand tomoroooooooooo
PolyInterfaces.pptnowand tomorooooooooooPolyInterfaces.pptnowand tomoroooooooooo
PolyInterfaces.pptnowand tomoroooooooooo
mugabecharles
 
Function overloading
Function overloadingFunction overloading
Function overloading
zindadili
 
Application package
Application packageApplication package
Application package
JAYAARC
 
polymorphism.pdf
polymorphism.pdfpolymorphism.pdf
polymorphism.pdf
riyawagh2
 
C++ programming introduction
C++ programming introductionC++ programming introduction
C++ programming introduction
sandeep54552
 
Polymorphism & Templates
Polymorphism & TemplatesPolymorphism & Templates
Polymorphism & Templates
Meghaj Mallick
 
Learn java lessons_online
Learn java lessons_onlineLearn java lessons_online
Learn java lessons_online
nishajj
 
Object Oriented Principles
Object Oriented PrinciplesObject Oriented Principles
Object Oriented Principles
Sujit Majety
 
Question and answer Programming
Question and answer ProgrammingQuestion and answer Programming
Question and answer Programming
Inocentshuja Ahmad
 
Learn C# Programming Polymorphism & Operator Overloading
Learn C# Programming Polymorphism & Operator OverloadingLearn C# Programming Polymorphism & Operator Overloading
Learn C# Programming Polymorphism & Operator Overloading
Eng Teong Cheah
 
Java OOPS Concept
Java OOPS ConceptJava OOPS Concept
Java OOPS Concept
Richa Gupta
 

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
MalligaarjunanN
 
Microprocessor and microcontroller record.pdf
Microprocessor and microcontroller record.pdfMicroprocessor and microcontroller record.pdf
Microprocessor and microcontroller record.pdf
MalligaarjunanN
 
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
MalligaarjunanN
 
8089 microprocessor with diagram and analytical
8089 microprocessor with diagram and analytical8089 microprocessor with diagram and analytical
8089 microprocessor with diagram and analytical
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.pptx
MalligaarjunanN
 
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
MalligaarjunanN
 
Technical English grammar and tenses.pptx
Technical English grammar and tenses.pptxTechnical English grammar and tenses.pptx
Technical English grammar and tenses.pptx
MalligaarjunanN
 
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
MalligaarjunanN
 
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
MalligaarjunanN
 
C programming DOC-20230723-WA0001..pptx
C programming  DOC-20230723-WA0001..pptxC programming  DOC-20230723-WA0001..pptx
C programming DOC-20230723-WA0001..pptx
MalligaarjunanN
 
Chemistry fluorescent topic chemistry.pptx
Chemistry fluorescent topic  chemistry.pptxChemistry fluorescent topic  chemistry.pptx
Chemistry fluorescent topic chemistry.pptx
MalligaarjunanN
 
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
MalligaarjunanN
 
Python programming file handling mhhk.pptx
Python programming file handling mhhk.pptxPython programming file handling mhhk.pptx
Python programming file handling mhhk.pptx
MalligaarjunanN
 
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
MalligaarjunanN
 
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
MalligaarjunanN
 
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
MalligaarjunanN
 
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
MalligaarjunanN
 
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 comment
MalligaarjunanN
 
pythoncommentsandvariables-231016105804-9a780b91 (1).pptx
pythoncommentsandvariables-231016105804-9a780b91 (1).pptxpythoncommentsandvariables-231016105804-9a780b91 (1).pptx
pythoncommentsandvariables-231016105804-9a780b91 (1).pptx
MalligaarjunanN
 
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
MalligaarjunanN
 
Microprocessor and microcontroller record.pdf
Microprocessor and microcontroller record.pdfMicroprocessor and microcontroller record.pdf
Microprocessor and microcontroller record.pdf
MalligaarjunanN
 
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
MalligaarjunanN
 
8089 microprocessor with diagram and analytical
8089 microprocessor with diagram and analytical8089 microprocessor with diagram and analytical
8089 microprocessor with diagram and analytical
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.pptx
MalligaarjunanN
 
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
MalligaarjunanN
 
Technical English grammar and tenses.pptx
Technical English grammar and tenses.pptxTechnical English grammar and tenses.pptx
Technical English grammar and tenses.pptx
MalligaarjunanN
 
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
MalligaarjunanN
 
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
MalligaarjunanN
 
C programming DOC-20230723-WA0001..pptx
C programming  DOC-20230723-WA0001..pptxC programming  DOC-20230723-WA0001..pptx
C programming DOC-20230723-WA0001..pptx
MalligaarjunanN
 
Chemistry fluorescent topic chemistry.pptx
Chemistry fluorescent topic  chemistry.pptxChemistry fluorescent topic  chemistry.pptx
Chemistry fluorescent topic chemistry.pptx
MalligaarjunanN
 
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
MalligaarjunanN
 
Python programming file handling mhhk.pptx
Python programming file handling mhhk.pptxPython programming file handling mhhk.pptx
Python programming file handling mhhk.pptx
MalligaarjunanN
 
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
MalligaarjunanN
 
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
MalligaarjunanN
 
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
MalligaarjunanN
 
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
MalligaarjunanN
 
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 comment
MalligaarjunanN
 
pythoncommentsandvariables-231016105804-9a780b91 (1).pptx
pythoncommentsandvariables-231016105804-9a780b91 (1).pptxpythoncommentsandvariables-231016105804-9a780b91 (1).pptx
pythoncommentsandvariables-231016105804-9a780b91 (1).pptx
MalligaarjunanN
 
Ad

Recently uploaded (20)

Level 1-Safety.pptx Presentation of Electrical Safety
Level 1-Safety.pptx Presentation of Electrical SafetyLevel 1-Safety.pptx Presentation of Electrical Safety
Level 1-Safety.pptx Presentation of Electrical Safety
JoseAlbertoCariasDel
 
Compiler Design Unit1 PPT Phases of Compiler.pptx
Compiler Design Unit1 PPT Phases of Compiler.pptxCompiler Design Unit1 PPT Phases of Compiler.pptx
Compiler Design Unit1 PPT Phases of Compiler.pptx
RushaliDeshmukh2
 
Raish Khanji GTU 8th sem Internship Report.pdf
Raish Khanji GTU 8th sem Internship Report.pdfRaish Khanji GTU 8th sem Internship Report.pdf
Raish Khanji GTU 8th sem Internship Report.pdf
RaishKhanji
 
introduction to machine learining for beginers
introduction to machine learining for beginersintroduction to machine learining for beginers
introduction to machine learining for beginers
JoydebSheet
 
Structural Response of Reinforced Self-Compacting Concrete Deep Beam Using Fi...
Structural Response of Reinforced Self-Compacting Concrete Deep Beam Using Fi...Structural Response of Reinforced Self-Compacting Concrete Deep Beam Using Fi...
Structural Response of Reinforced Self-Compacting Concrete Deep Beam Using Fi...
Journal of Soft Computing in Civil Engineering
 
Compiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptxCompiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptx
RushaliDeshmukh2
 
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E..."Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
Infopitaara
 
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdfRICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
MohamedAbdelkader115
 
Smart Storage Solutions.pptx for production engineering
Smart Storage Solutions.pptx for production engineeringSmart Storage Solutions.pptx for production engineering
Smart Storage Solutions.pptx for production engineering
rushikeshnavghare94
 
Degree_of_Automation.pdf for Instrumentation and industrial specialist
Degree_of_Automation.pdf for  Instrumentation  and industrial specialistDegree_of_Automation.pdf for  Instrumentation  and industrial specialist
Degree_of_Automation.pdf for Instrumentation and industrial specialist
shreyabhosale19
 
Introduction to FLUID MECHANICS & KINEMATICS
Introduction to FLUID MECHANICS &  KINEMATICSIntroduction to FLUID MECHANICS &  KINEMATICS
Introduction to FLUID MECHANICS & KINEMATICS
narayanaswamygdas
 
Artificial Intelligence (AI) basics.pptx
Artificial Intelligence (AI) basics.pptxArtificial Intelligence (AI) basics.pptx
Artificial Intelligence (AI) basics.pptx
aditichinar
 
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
charlesdick1345
 
new ppt artificial intelligence historyyy
new ppt artificial intelligence historyyynew ppt artificial intelligence historyyy
new ppt artificial intelligence historyyy
PianoPianist
 
IntroSlides-April-BuildWithAI-VertexAI.pdf
IntroSlides-April-BuildWithAI-VertexAI.pdfIntroSlides-April-BuildWithAI-VertexAI.pdf
IntroSlides-April-BuildWithAI-VertexAI.pdf
Luiz Carneiro
 
Introduction to Zoomlion Earthmoving.pptx
Introduction to Zoomlion Earthmoving.pptxIntroduction to Zoomlion Earthmoving.pptx
Introduction to Zoomlion Earthmoving.pptx
AS1920
 
QA/QC Manager (Quality management Expert)
QA/QC Manager (Quality management Expert)QA/QC Manager (Quality management Expert)
QA/QC Manager (Quality management Expert)
rccbatchplant
 
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptxExplainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
MahaveerVPandit
 
π0.5: a Vision-Language-Action Model with Open-World Generalization
π0.5: a Vision-Language-Action Model with Open-World Generalizationπ0.5: a Vision-Language-Action Model with Open-World Generalization
π0.5: a Vision-Language-Action Model with Open-World Generalization
NABLAS株式会社
 
some basics electrical and electronics knowledge
some basics electrical and electronics knowledgesome basics electrical and electronics knowledge
some basics electrical and electronics knowledge
nguyentrungdo88
 
Level 1-Safety.pptx Presentation of Electrical Safety
Level 1-Safety.pptx Presentation of Electrical SafetyLevel 1-Safety.pptx Presentation of Electrical Safety
Level 1-Safety.pptx Presentation of Electrical Safety
JoseAlbertoCariasDel
 
Compiler Design Unit1 PPT Phases of Compiler.pptx
Compiler Design Unit1 PPT Phases of Compiler.pptxCompiler Design Unit1 PPT Phases of Compiler.pptx
Compiler Design Unit1 PPT Phases of Compiler.pptx
RushaliDeshmukh2
 
Raish Khanji GTU 8th sem Internship Report.pdf
Raish Khanji GTU 8th sem Internship Report.pdfRaish Khanji GTU 8th sem Internship Report.pdf
Raish Khanji GTU 8th sem Internship Report.pdf
RaishKhanji
 
introduction to machine learining for beginers
introduction to machine learining for beginersintroduction to machine learining for beginers
introduction to machine learining for beginers
JoydebSheet
 
Compiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptxCompiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptx
RushaliDeshmukh2
 
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E..."Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
Infopitaara
 
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdfRICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
MohamedAbdelkader115
 
Smart Storage Solutions.pptx for production engineering
Smart Storage Solutions.pptx for production engineeringSmart Storage Solutions.pptx for production engineering
Smart Storage Solutions.pptx for production engineering
rushikeshnavghare94
 
Degree_of_Automation.pdf for Instrumentation and industrial specialist
Degree_of_Automation.pdf for  Instrumentation  and industrial specialistDegree_of_Automation.pdf for  Instrumentation  and industrial specialist
Degree_of_Automation.pdf for Instrumentation and industrial specialist
shreyabhosale19
 
Introduction to FLUID MECHANICS & KINEMATICS
Introduction to FLUID MECHANICS &  KINEMATICSIntroduction to FLUID MECHANICS &  KINEMATICS
Introduction to FLUID MECHANICS & KINEMATICS
narayanaswamygdas
 
Artificial Intelligence (AI) basics.pptx
Artificial Intelligence (AI) basics.pptxArtificial Intelligence (AI) basics.pptx
Artificial Intelligence (AI) basics.pptx
aditichinar
 
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
charlesdick1345
 
new ppt artificial intelligence historyyy
new ppt artificial intelligence historyyynew ppt artificial intelligence historyyy
new ppt artificial intelligence historyyy
PianoPianist
 
IntroSlides-April-BuildWithAI-VertexAI.pdf
IntroSlides-April-BuildWithAI-VertexAI.pdfIntroSlides-April-BuildWithAI-VertexAI.pdf
IntroSlides-April-BuildWithAI-VertexAI.pdf
Luiz Carneiro
 
Introduction to Zoomlion Earthmoving.pptx
Introduction to Zoomlion Earthmoving.pptxIntroduction to Zoomlion Earthmoving.pptx
Introduction to Zoomlion Earthmoving.pptx
AS1920
 
QA/QC Manager (Quality management Expert)
QA/QC Manager (Quality management Expert)QA/QC Manager (Quality management Expert)
QA/QC Manager (Quality management Expert)
rccbatchplant
 
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptxExplainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
MahaveerVPandit
 
π0.5: a Vision-Language-Action Model with Open-World Generalization
π0.5: a Vision-Language-Action Model with Open-World Generalizationπ0.5: a Vision-Language-Action Model with Open-World Generalization
π0.5: a Vision-Language-Action Model with Open-World Generalization
NABLAS株式会社
 
some basics electrical and electronics knowledge
some basics electrical and electronics knowledgesome basics electrical and electronics knowledge
some basics electrical and electronics knowledge
nguyentrungdo88
 
Ad

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'