SlideShare a Scribd company logo
1 of 20
Download to read offline
Computer Science Faculty/Kabul University
Polymorphism in Object Oriented Programming (OOP)
Polymorphism in OOP
Supervisor: Prof. Abdul Rahman Mujadadi
Presentor: M. Mustafa Ibrahimy
18, Oct, 2017
Computer Science Faculty/Kabul University
Polymorphism in Object Oriented Programming (OOP)
Contents
• Introduction
• What is Polymorphism?
• Advantages & Disadvantages
• Types of Polymorphisms
• Conclusion
2
Computer Science Faculty/Kabul University
Polymorphism in Object Oriented Programming (OOP)
Aim of Today’s Seminar
• To introduce polymorphism in OOP
3
Computer Science Faculty/Kabul University
Polymorphism in Object Oriented Programming (OOP)
4
- It is one of the important concept of OOP
- With polymorphism can design, implement
systems which are extensible.
- New classes can be added with little or without
modification in general portions of the program
[3].
Introduction
Computer Science Faculty/Kabul University
Polymorphism in Object Oriented Programming (OOP)
What is Polymorphism?
Definitions:
• The process of representing one form in multiple
forms is known as Polymorphism [2].
• The ability to take more than one form is called
polymorphism [1].
• Polymorphism is derived from 2 Greek
words: poly and morphs. It means many
forms[2].
5
Computer Science Faculty/Kabul University
Polymorphism in Object Oriented Programming (OOP)
Real life example of polymorphism
6
[2]
Computer Science Faculty/Kabul University
Polymorphism in Object Oriented Programming (OOP)
Important PointsAbout Polymorphism
• The behavior depends on the type of data used in
the operation
• Polymorphism is used for implementing
inheritance. [4]
7
Computer Science Faculty/Kabul University
Polymorphism in Object Oriented Programming (OOP)
Advantages Of Polymorphism
• It helps programmers reuse the code and classes
once written, tested and implemented. They can be
reused in many ways.
• Single variable name can be used to store variables
of multiple data types(Float, double, Long, Int
etc) [5].
8
Computer Science Faculty/Kabul University
Polymorphism in Object Oriented Programming (OOP)
Disadvantages Of Polymorphism
• developers find it difficult to implement
polymorphism in codes.
• Polymorphism reduces the readability of the
program [5].
9
Computer Science Faculty/Kabul University
Polymorphism in Object Oriented Programming (OOP)
Types of Polymorphism
Polymorphism is divided into two types:
1) Method overloading (compile time)
It is also known as Static binding, Early binding
2) Method overriding (run time)
It is also known as Dynamic binding, Late binding.
10
Computer Science Faculty/Kabul University
Polymorphism in Object Oriented Programming (OOP)
Continue…
Static binding: happens at compile time
Dynamic binding: happens at runtime
Dynamic Binding: is the process of linking
procedure call to a specific sequence of code
(method) at run-time. It means that the code to be
executed for a specific procedure call is not known
until run-time [5].
11
Computer Science Faculty/Kabul University
Polymorphism in Object Oriented Programming (OOP)
Method Overloading
• In method overloading, a class has multiple
methods with same name but different
parameters.
• We can achieve method overloading by changing
parameter types or by changing the number of
parameters [4].
12
Computer Science Faculty/Kabul University
Polymorphism in Object Oriented Programming (OOP)
Method overloading -Example
public class OverLoading {
static class Mthdoverloading {
void test() {
System.out.println("No parameters");
}
//Overload test for one integer parameter.
void test(int a) {
System.out.println("a: "+a);
}
//Overload test for two integer parameters.
void test(int a, int b) {
System.out.println("a and b: " + a + " " +b);
}
} 13
Computer Science Faculty/Kabul University
Polymorphism in Object Oriented Programming (OOP)
Continue…
public static void main(String[] args) {
Mthdoverloading ob= new
Mthdoverloading();
ob.test();
ob.test(10);
ob.test(10,20);
}
}
Output:
No parameters
a: 10
a and b: 10 20
14
Computer Science Faculty/Kabul University
Polymorphism in Object Oriented Programming (OOP)
Method Overriding
15
• In method overriding, super class and sub
class having methods with same name and
same parameters but having different
implementations [4].
Computer Science Faculty/Kabul University
Polymorphism in Object Oriented Programming (OOP)
Method Overriding -Example
16
public class Overriding {
static class Animal {
public void move() {
System.out.println("Animals can move");
}
}
static class Dog extends Animal {
@Override
public void move() {
//invokes the super class method
System.out.println("Dogs can walk and run");
}
}
Computer Science Faculty/Kabul University
Polymorphism in Object Oriented Programming (OOP)
Continue…
17
static class Bird extends Animal {
@Override
public void move() {
//invokes the super class method
System.out.println("Birds can fly");
}
}
public static void main(String[] args) {
Dog obj = new Dog();
obj.move();
Bird b = new Bird();
b.move();
}
}
Output:
Dogs can walk and run
Birds can fly
Computer Science Faculty/Kabul University
Polymorphism in Object Oriented Programming (OOP)
Conclusion
Polymorphism:
- An important OOP concept
- Act differently under different context.
Method overloading increases the readability of the
program.
Method overriding is used to achieve run-time
polymorphism.
18
Computer Science Faculty/Kabul University
Polymorphism in Object Oriented Programming (OOP)
References
[1] T.P, Abbas. (2010). Data Structures & OOP Using C++,
Kerala: Calicut University Central Co-operative Store
[2] Kumar, Hitesh.(2013). Java Polymorphism. Retrieved 2017,
Oct 14, from https://www.sitesbay.com
[3] Oruji, Amin.(2013, December). OOP-Polymorphism.
Retrieved 2017, Oct 14, from https://www.oruji.org
[4] Christensson, P. (2007, November 2). OOP Definition.
Retrieved 2017, Oct 14, from https://techterms.com
[5] Sparrow, Penna.(2010, June). OOP-Polymorphism.
Retrieved 2017, Oct 17, from http://www.ianswer4u.com
19
Computer Science Faculty/Kabul University
Polymorphism in Object Oriented Programming (OOP)
Any Question
Thanks
20

More Related Content

What's hot

Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming Concepts
thinkphp
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Java
backdoor
 

What's hot (20)

Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Polymorphism in c++(ppt)
Polymorphism in c++(ppt)Polymorphism in c++(ppt)
Polymorphism in c++(ppt)
 
polymorphism ppt
polymorphism pptpolymorphism ppt
polymorphism ppt
 
Basic concepts of object oriented programming
Basic concepts of object oriented programmingBasic concepts of object oriented programming
Basic concepts of object oriented programming
 
Inheritance in OOPS
Inheritance in OOPSInheritance in OOPS
Inheritance in OOPS
 
Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming Concepts
 
OOP - Polymorphism
OOP - PolymorphismOOP - Polymorphism
OOP - Polymorphism
 
OOPS Basics With Example
OOPS Basics With ExampleOOPS Basics With Example
OOPS Basics With Example
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Java
 
Object oriented programming c++
Object oriented programming c++Object oriented programming c++
Object oriented programming c++
 
Interface in java
Interface in javaInterface in java
Interface in java
 
Oop Presentation
Oop PresentationOop Presentation
Oop Presentation
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
 
Polymorphism In Java
Polymorphism In JavaPolymorphism In Java
Polymorphism In Java
 
C++ concept of Polymorphism
C++ concept of  PolymorphismC++ concept of  Polymorphism
C++ concept of Polymorphism
 
Oops concepts || Object Oriented Programming Concepts in Java
Oops concepts || Object Oriented Programming Concepts in JavaOops concepts || Object Oriented Programming Concepts in Java
Oops concepts || Object Oriented Programming Concepts in Java
 
Java abstract class & abstract methods
Java abstract class & abstract methodsJava abstract class & abstract methods
Java abstract class & abstract methods
 

Similar to Polymorphism in oop

Object Oriented programming Using Python.pdf
Object Oriented programming Using Python.pdfObject Oriented programming Using Python.pdf
Object Oriented programming Using Python.pdf
RishuRaj953240
 
9-_Object_Oriented_Programming_Using_Python.pdf
9-_Object_Oriented_Programming_Using_Python.pdf9-_Object_Oriented_Programming_Using_Python.pdf
9-_Object_Oriented_Programming_Using_Python.pdf
anaveenkumar4
 

Similar to Polymorphism in oop (20)

Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Polymorphism in java
Polymorphism in java Polymorphism in java
Polymorphism in java
 
Oops in PHP By Nyros Developer
Oops in PHP By Nyros DeveloperOops in PHP By Nyros Developer
Oops in PHP By Nyros Developer
 
C++ first s lide
C++ first s lideC++ first s lide
C++ first s lide
 
Learn java lessons_online
Learn java lessons_onlineLearn java lessons_online
Learn java lessons_online
 
Java(Polymorphism)
Java(Polymorphism)Java(Polymorphism)
Java(Polymorphism)
 
Object Oriented programming Using Python.pdf
Object Oriented programming Using Python.pdfObject Oriented programming Using Python.pdf
Object Oriented programming Using Python.pdf
 
9-_Object_Oriented_Programming_Using_Python.pdf
9-_Object_Oriented_Programming_Using_Python.pdf9-_Object_Oriented_Programming_Using_Python.pdf
9-_Object_Oriented_Programming_Using_Python.pdf
 
Need of object oriented programming
Need of object oriented programmingNeed of object oriented programming
Need of object oriented programming
 
Polymorphism in Python
Polymorphism in PythonPolymorphism in Python
Polymorphism in Python
 
object oriented programming(oops)
object oriented programming(oops)object oriented programming(oops)
object oriented programming(oops)
 
Object Oriented Programming.pptx
 Object Oriented Programming.pptx Object Oriented Programming.pptx
Object Oriented Programming.pptx
 
L03 Software Design
L03 Software DesignL03 Software Design
L03 Software Design
 
JavaHTP6e_10.ppt
JavaHTP6e_10.pptJavaHTP6e_10.ppt
JavaHTP6e_10.ppt
 
Be cse
Be cseBe cse
Be cse
 
What is OOP_ (Object Oriented Programming) (1).pptx
What is OOP_ (Object Oriented Programming) (1).pptxWhat is OOP_ (Object Oriented Programming) (1).pptx
What is OOP_ (Object Oriented Programming) (1).pptx
 
Object Oriented Programming Overview for the PeopleSoft Developer
Object Oriented Programming Overview for the PeopleSoft DeveloperObject Oriented Programming Overview for the PeopleSoft Developer
Object Oriented Programming Overview for the PeopleSoft Developer
 
Bca 2nd sem u-1 iintroduction
Bca 2nd sem u-1 iintroductionBca 2nd sem u-1 iintroduction
Bca 2nd sem u-1 iintroduction
 
Lecture01
Lecture01Lecture01
Lecture01
 
Design Pattern Mastery - Momentum Dev Con 19 Apr 2018
Design Pattern Mastery - Momentum Dev Con 19 Apr 2018Design Pattern Mastery - Momentum Dev Con 19 Apr 2018
Design Pattern Mastery - Momentum Dev Con 19 Apr 2018
 

Recently uploaded

Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
MateoGardella
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
SanaAli374401
 

Recently uploaded (20)

ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 

Polymorphism in oop

  • 1. Computer Science Faculty/Kabul University Polymorphism in Object Oriented Programming (OOP) Polymorphism in OOP Supervisor: Prof. Abdul Rahman Mujadadi Presentor: M. Mustafa Ibrahimy 18, Oct, 2017
  • 2. Computer Science Faculty/Kabul University Polymorphism in Object Oriented Programming (OOP) Contents • Introduction • What is Polymorphism? • Advantages & Disadvantages • Types of Polymorphisms • Conclusion 2
  • 3. Computer Science Faculty/Kabul University Polymorphism in Object Oriented Programming (OOP) Aim of Today’s Seminar • To introduce polymorphism in OOP 3
  • 4. Computer Science Faculty/Kabul University Polymorphism in Object Oriented Programming (OOP) 4 - It is one of the important concept of OOP - With polymorphism can design, implement systems which are extensible. - New classes can be added with little or without modification in general portions of the program [3]. Introduction
  • 5. Computer Science Faculty/Kabul University Polymorphism in Object Oriented Programming (OOP) What is Polymorphism? Definitions: • The process of representing one form in multiple forms is known as Polymorphism [2]. • The ability to take more than one form is called polymorphism [1]. • Polymorphism is derived from 2 Greek words: poly and morphs. It means many forms[2]. 5
  • 6. Computer Science Faculty/Kabul University Polymorphism in Object Oriented Programming (OOP) Real life example of polymorphism 6 [2]
  • 7. Computer Science Faculty/Kabul University Polymorphism in Object Oriented Programming (OOP) Important PointsAbout Polymorphism • The behavior depends on the type of data used in the operation • Polymorphism is used for implementing inheritance. [4] 7
  • 8. Computer Science Faculty/Kabul University Polymorphism in Object Oriented Programming (OOP) Advantages Of Polymorphism • It helps programmers reuse the code and classes once written, tested and implemented. They can be reused in many ways. • Single variable name can be used to store variables of multiple data types(Float, double, Long, Int etc) [5]. 8
  • 9. Computer Science Faculty/Kabul University Polymorphism in Object Oriented Programming (OOP) Disadvantages Of Polymorphism • developers find it difficult to implement polymorphism in codes. • Polymorphism reduces the readability of the program [5]. 9
  • 10. Computer Science Faculty/Kabul University Polymorphism in Object Oriented Programming (OOP) Types of Polymorphism Polymorphism is divided into two types: 1) Method overloading (compile time) It is also known as Static binding, Early binding 2) Method overriding (run time) It is also known as Dynamic binding, Late binding. 10
  • 11. Computer Science Faculty/Kabul University Polymorphism in Object Oriented Programming (OOP) Continue… Static binding: happens at compile time Dynamic binding: happens at runtime Dynamic Binding: is the process of linking procedure call to a specific sequence of code (method) at run-time. It means that the code to be executed for a specific procedure call is not known until run-time [5]. 11
  • 12. Computer Science Faculty/Kabul University Polymorphism in Object Oriented Programming (OOP) Method Overloading • In method overloading, a class has multiple methods with same name but different parameters. • We can achieve method overloading by changing parameter types or by changing the number of parameters [4]. 12
  • 13. Computer Science Faculty/Kabul University Polymorphism in Object Oriented Programming (OOP) Method overloading -Example public class OverLoading { static class Mthdoverloading { void test() { System.out.println("No parameters"); } //Overload test for one integer parameter. void test(int a) { System.out.println("a: "+a); } //Overload test for two integer parameters. void test(int a, int b) { System.out.println("a and b: " + a + " " +b); } } 13
  • 14. Computer Science Faculty/Kabul University Polymorphism in Object Oriented Programming (OOP) Continue… public static void main(String[] args) { Mthdoverloading ob= new Mthdoverloading(); ob.test(); ob.test(10); ob.test(10,20); } } Output: No parameters a: 10 a and b: 10 20 14
  • 15. Computer Science Faculty/Kabul University Polymorphism in Object Oriented Programming (OOP) Method Overriding 15 • In method overriding, super class and sub class having methods with same name and same parameters but having different implementations [4].
  • 16. Computer Science Faculty/Kabul University Polymorphism in Object Oriented Programming (OOP) Method Overriding -Example 16 public class Overriding { static class Animal { public void move() { System.out.println("Animals can move"); } } static class Dog extends Animal { @Override public void move() { //invokes the super class method System.out.println("Dogs can walk and run"); } }
  • 17. Computer Science Faculty/Kabul University Polymorphism in Object Oriented Programming (OOP) Continue… 17 static class Bird extends Animal { @Override public void move() { //invokes the super class method System.out.println("Birds can fly"); } } public static void main(String[] args) { Dog obj = new Dog(); obj.move(); Bird b = new Bird(); b.move(); } } Output: Dogs can walk and run Birds can fly
  • 18. Computer Science Faculty/Kabul University Polymorphism in Object Oriented Programming (OOP) Conclusion Polymorphism: - An important OOP concept - Act differently under different context. Method overloading increases the readability of the program. Method overriding is used to achieve run-time polymorphism. 18
  • 19. Computer Science Faculty/Kabul University Polymorphism in Object Oriented Programming (OOP) References [1] T.P, Abbas. (2010). Data Structures & OOP Using C++, Kerala: Calicut University Central Co-operative Store [2] Kumar, Hitesh.(2013). Java Polymorphism. Retrieved 2017, Oct 14, from https://www.sitesbay.com [3] Oruji, Amin.(2013, December). OOP-Polymorphism. Retrieved 2017, Oct 14, from https://www.oruji.org [4] Christensson, P. (2007, November 2). OOP Definition. Retrieved 2017, Oct 14, from https://techterms.com [5] Sparrow, Penna.(2010, June). OOP-Polymorphism. Retrieved 2017, Oct 17, from http://www.ianswer4u.com 19
  • 20. Computer Science Faculty/Kabul University Polymorphism in Object Oriented Programming (OOP) Any Question Thanks 20