SlideShare a Scribd company logo
Polymorphism
Rencana Pembelajaran
Standart Capaian Lulusan
Capaian Pembelajaran
Mata Kuliah
MATERI
Standart Capaian Lulusan
Menguasai konsep teoritis dan mampu
menerapkan kemampuan mendalam pada
bahasa pemrograman untuk merancang
software aplikasi dan sistem informasi yang
sedang trend pada masanya dengan
menunjukkan kinerja mandiri, bermutu, dan
terukur serta bertanggung jawab atas
pekerjaan di bidang keahliannya.
Capaian Pembelajaran
Mata Kuliah
Merancang dan membuat program dengan
menerapkan konsep Polymorphism.
Polymorphism
It is a mechanism which allows to have many
forms of the method having the same name.
(Polymorphism isthe ability of an object to take
on many forms)
The most common use of polymorphism inOOP
occurs when a parent class referenceis used to
refer to a child class object.
Types of polym3
orphism in3/24/20
java
There are two types of polymorphism in Java:
Runtimepolymorphism(Dynamic
polymorphism)
Compiletimepolymorphism (Static
polymorphism).
Runtime Polymorphism
(Dynamic polymorphism)
Method overriding is a perfect example of
runtime polymorphism.
In this kind of polymorphism, reference of class Xcan
hold object of class X or an object of any sub classes
of class X.
For e.g. if class Y extends class X then both ofthe
following statements are valid:
Y obj = new Y();
//Parent class reference can be assigned to child
object
X obj = new Y();
Cont..,
Since in method overriding both the classes(baseclass
andchild class)havesamemethod,compile doesn’t
figure out which method to call at compile-time.
In this case JVM (Java Virtual Machine) decides
which method tocall at runtime that’s why it is
known as runtime or dynamic polymorphism.
Example
public class A {
public void methodA() { //Base class method System.out.println("methodA of
class A");
} }
public class B extends A {
public void methodA() { //Derived Class method System.out.println
("methodA of class B");
} }
public class Z {
public static void main (String args []) { A obj1 = new A();
// Reference and objectB
A obj2 = new B(); // A reference but B object
obj1.methodA();
obj2.methodA();
}
Output:
methodA of class A
}
Note:As you can see the methodA has different-2 forms in child and
parent class thus we can say methodA here is polymorphic.
Compile time Polymorphism (Static
polymorphism)
Compile time polymorphism is nothing but the
method overloading in java.
In simple terms we can say that a class can have more
than one methods with same name but with different
number of arguments or different types of arguments or
both.
Example
class X {
void methodA(int num) {
System.out.println ("methodA: " + num);
}
void methodA(int n1, int n2) {
System.out.println ("methodA: "+ n1 +“, "+ n2);
}
}
public class Y {
public static void main (String args []) { X Obj = new X();
double result;
Obj. methodA(20); Obj.
methodA(20, 30);
Output:
methodA: 20
}
}
Note: The class has 2 variance of methodA or we can say methodA is polymorphic
in nature since it is having 2 different forms. In such scenario, compiler is able to
figure out the method call at compile- time that’s the reason it is known as compile
time pSoalymmpaothrpKhumisamrS.,AP
Thank You
Sampath Kumar S, AP

More Related Content

What's hot (20)

PDF
Object-Oriented Polymorphism Unleashed
Naresh Chintalcheru
 
PPT
JAVA Polymorphism
Mahi Mca
 
PPT
Introduction to method overloading & method overriding in java hdm
Harshal Misalkar
 
PDF
Method Overloading In Java
CharthaGaglani
 
PPTX
Polymorphism
Ahmed Za'anin
 
PDF
Polymorphism In Java
Spotle.ai
 
PPT
Polymorphism
Kumar
 
PPTX
Polymorphism in java
sureshraj43
 
PPTX
Polymorphism in java
Janu Jahnavi
 
PPTX
OOP - Polymorphism
Mudasir Qazi
 
PPTX
Polymorphism
Arif Ansari
 
PPTX
Inheritance and Polymorphism Java
M. Raihan
 
PDF
Learn java lessons_online
nishajj
 
PPTX
Polymorphism in Python
Home
 
ODP
OOP java
xball977
 
PPTX
polymorphism
Imtiaz Hussain
 
PPT
Static and Dynamic polymorphism in C++
Anil Bapat
 
PPTX
oops concept in java | object oriented programming in java
CPD INDIA
 
PPTX
28csharp
Sireesh K
 
PPT
Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...
cprogrammings
 
Object-Oriented Polymorphism Unleashed
Naresh Chintalcheru
 
JAVA Polymorphism
Mahi Mca
 
Introduction to method overloading & method overriding in java hdm
Harshal Misalkar
 
Method Overloading In Java
CharthaGaglani
 
Polymorphism
Ahmed Za'anin
 
Polymorphism In Java
Spotle.ai
 
Polymorphism
Kumar
 
Polymorphism in java
sureshraj43
 
Polymorphism in java
Janu Jahnavi
 
OOP - Polymorphism
Mudasir Qazi
 
Polymorphism
Arif Ansari
 
Inheritance and Polymorphism Java
M. Raihan
 
Learn java lessons_online
nishajj
 
Polymorphism in Python
Home
 
OOP java
xball977
 
polymorphism
Imtiaz Hussain
 
Static and Dynamic polymorphism in C++
Anil Bapat
 
oops concept in java | object oriented programming in java
CPD INDIA
 
28csharp
Sireesh K
 
Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...
cprogrammings
 

Similar to P.7 media 2 polymorphism (20)

PPTX
java poly ppt.pptx
sukhpreetsingh295239
 
PPTX
Java(Polymorphism)
harsh kothari
 
PDF
Java Polymorphism: Types And Examples (Geekster)
Geekster
 
PPTX
Basics of polymorphism underlying hhhhhhh
dikshaprabhugvm
 
PPTX
JAVA_POLYMORPHISM.pptx
Hitesh Kumar Nath
 
PPTX
Presentstion polymorphism opp Java muet u
Anjali127411
 
PDF
Java Polymorphism
Soba Arjun
 
PPTX
Chapter8:Understanding Polymorphism
It Academy
 
PDF
Polymorphism in Java by Animesh Sarkar
Animesh Sarkar
 
PPTX
OOP- PolymorphismFinal12injavait101.pptx
codevincent624
 
PDF
Object Oriented Programming - 7.2. Polymorphism
AndiNurkholis1
 
PPTX
Polymorphism
Ducat India
 
PPTX
java polymorphism example program oracal.pptx
pirito8705
 
PPTX
Polymorphism OOP new Gate.pptx
AssadLeo1
 
PPTX
Polymorphism OOP Old Gate.pptx
AssadLeo1
 
PPTX
Oop lecture 06
University of Chitral
 
PPTX
Polymorphism.pptx
RiturajJain8
 
PPTX
Advance Java Polymorphism OOPS CON .pptx
jprince1621
 
PPTX
AkhileshD_Presentation_Core_Java_OOPs.pptx
Akhilesh740777
 
PPT
Java Programming - Polymorphism
Oum Saokosal
 
java poly ppt.pptx
sukhpreetsingh295239
 
Java(Polymorphism)
harsh kothari
 
Java Polymorphism: Types And Examples (Geekster)
Geekster
 
Basics of polymorphism underlying hhhhhhh
dikshaprabhugvm
 
JAVA_POLYMORPHISM.pptx
Hitesh Kumar Nath
 
Presentstion polymorphism opp Java muet u
Anjali127411
 
Java Polymorphism
Soba Arjun
 
Chapter8:Understanding Polymorphism
It Academy
 
Polymorphism in Java by Animesh Sarkar
Animesh Sarkar
 
OOP- PolymorphismFinal12injavait101.pptx
codevincent624
 
Object Oriented Programming - 7.2. Polymorphism
AndiNurkholis1
 
Polymorphism
Ducat India
 
java polymorphism example program oracal.pptx
pirito8705
 
Polymorphism OOP new Gate.pptx
AssadLeo1
 
Polymorphism OOP Old Gate.pptx
AssadLeo1
 
Oop lecture 06
University of Chitral
 
Polymorphism.pptx
RiturajJain8
 
Advance Java Polymorphism OOPS CON .pptx
jprince1621
 
AkhileshD_Presentation_Core_Java_OOPs.pptx
Akhilesh740777
 
Java Programming - Polymorphism
Oum Saokosal
 
Ad

More from ahmadmuzaqqi (19)

PPTX
Virtual lan
ahmadmuzaqqi
 
PPTX
Subnetting
ahmadmuzaqqi
 
PPTX
Model osi dan tcp
ahmadmuzaqqi
 
PPTX
Pengkabelan
ahmadmuzaqqi
 
PPTX
Routing
ahmadmuzaqqi
 
PPT
5 fungsi
ahmadmuzaqqi
 
PPT
4 matriks dan relasi
ahmadmuzaqqi
 
PPT
3 himpunan
ahmadmuzaqqi
 
PPT
2 proposisi
ahmadmuzaqqi
 
PPT
1 logika
ahmadmuzaqqi
 
PPTX
Ppt modul 5 array
ahmadmuzaqqi
 
PPTX
Ppt modul 6 fungsi
ahmadmuzaqqi
 
PPTX
Ppt modul 4 perulangan
ahmadmuzaqqi
 
PPTX
Ppt modul 3 operasi kondisi
ahmadmuzaqqi
 
PPTX
Ppt modul 2 operator
ahmadmuzaqqi
 
PPTX
P.9 media 2 konsep inheritance
ahmadmuzaqqi
 
PPTX
P.5 media 2 enkapsulasi
ahmadmuzaqqi
 
PPTX
P.3 media 2 class, objek, method pada java
ahmadmuzaqqi
 
PPTX
Sejarah Java
ahmadmuzaqqi
 
Virtual lan
ahmadmuzaqqi
 
Subnetting
ahmadmuzaqqi
 
Model osi dan tcp
ahmadmuzaqqi
 
Pengkabelan
ahmadmuzaqqi
 
Routing
ahmadmuzaqqi
 
5 fungsi
ahmadmuzaqqi
 
4 matriks dan relasi
ahmadmuzaqqi
 
3 himpunan
ahmadmuzaqqi
 
2 proposisi
ahmadmuzaqqi
 
1 logika
ahmadmuzaqqi
 
Ppt modul 5 array
ahmadmuzaqqi
 
Ppt modul 6 fungsi
ahmadmuzaqqi
 
Ppt modul 4 perulangan
ahmadmuzaqqi
 
Ppt modul 3 operasi kondisi
ahmadmuzaqqi
 
Ppt modul 2 operator
ahmadmuzaqqi
 
P.9 media 2 konsep inheritance
ahmadmuzaqqi
 
P.5 media 2 enkapsulasi
ahmadmuzaqqi
 
P.3 media 2 class, objek, method pada java
ahmadmuzaqqi
 
Sejarah Java
ahmadmuzaqqi
 
Ad

Recently uploaded (20)

PPTX
PROTIEN ENERGY MALNUTRITION: NURSING MANAGEMENT.pptx
PRADEEP ABOTHU
 
PPTX
20250924 Navigating the Future: How to tell the difference between an emergen...
McGuinness Institute
 
PPTX
YSPH VMOC Special Report - Measles Outbreak Southwest US 7-20-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
PPTX
Translation_ Definition, Scope & Historical Development.pptx
DhatriParmar
 
PPTX
How to Track Skills & Contracts Using Odoo 18 Employee
Celine George
 
PPTX
Artificial Intelligence in Gastroentrology: Advancements and Future Presprec...
AyanHossain
 
PPTX
Top 10 AI Tools, Like ChatGPT. You Must Learn In 2025
Digilearnings
 
PPTX
Unlock the Power of Cursor AI: MuleSoft Integrations
Veera Pallapu
 
PPTX
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
PDF
Module 2: Public Health History [Tutorial Slides]
JonathanHallett4
 
PPTX
HEALTH CARE DELIVERY SYSTEM - UNIT 2 - GNM 3RD YEAR.pptx
Priyanshu Anand
 
PDF
The-Invisible-Living-World-Beyond-Our-Naked-Eye chapter 2.pdf/8th science cur...
Sandeep Swamy
 
PPTX
Applied-Statistics-1.pptx hardiba zalaaa
hardizala899
 
PPTX
Digital Professionalism and Interpersonal Competence
rutvikgediya1
 
PDF
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
DOCX
Modul Ajar Deep Learning Bahasa Inggris Kelas 11 Terbaru 2025
wahyurestu63
 
PPTX
Gupta Art & Architecture Temple and Sculptures.pptx
Virag Sontakke
 
PDF
John Keats introduction and list of his important works
vatsalacpr
 
PPTX
Cleaning Validation Ppt Pharmaceutical validation
Ms. Ashatai Patil
 
PPTX
CONCEPT OF CHILD CARE. pptx
AneetaSharma15
 
PROTIEN ENERGY MALNUTRITION: NURSING MANAGEMENT.pptx
PRADEEP ABOTHU
 
20250924 Navigating the Future: How to tell the difference between an emergen...
McGuinness Institute
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 7-20-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
Translation_ Definition, Scope & Historical Development.pptx
DhatriParmar
 
How to Track Skills & Contracts Using Odoo 18 Employee
Celine George
 
Artificial Intelligence in Gastroentrology: Advancements and Future Presprec...
AyanHossain
 
Top 10 AI Tools, Like ChatGPT. You Must Learn In 2025
Digilearnings
 
Unlock the Power of Cursor AI: MuleSoft Integrations
Veera Pallapu
 
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
Module 2: Public Health History [Tutorial Slides]
JonathanHallett4
 
HEALTH CARE DELIVERY SYSTEM - UNIT 2 - GNM 3RD YEAR.pptx
Priyanshu Anand
 
The-Invisible-Living-World-Beyond-Our-Naked-Eye chapter 2.pdf/8th science cur...
Sandeep Swamy
 
Applied-Statistics-1.pptx hardiba zalaaa
hardizala899
 
Digital Professionalism and Interpersonal Competence
rutvikgediya1
 
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
Modul Ajar Deep Learning Bahasa Inggris Kelas 11 Terbaru 2025
wahyurestu63
 
Gupta Art & Architecture Temple and Sculptures.pptx
Virag Sontakke
 
John Keats introduction and list of his important works
vatsalacpr
 
Cleaning Validation Ppt Pharmaceutical validation
Ms. Ashatai Patil
 
CONCEPT OF CHILD CARE. pptx
AneetaSharma15
 

P.7 media 2 polymorphism

  • 2. Rencana Pembelajaran Standart Capaian Lulusan Capaian Pembelajaran Mata Kuliah MATERI
  • 3. Standart Capaian Lulusan Menguasai konsep teoritis dan mampu menerapkan kemampuan mendalam pada bahasa pemrograman untuk merancang software aplikasi dan sistem informasi yang sedang trend pada masanya dengan menunjukkan kinerja mandiri, bermutu, dan terukur serta bertanggung jawab atas pekerjaan di bidang keahliannya.
  • 4. Capaian Pembelajaran Mata Kuliah Merancang dan membuat program dengan menerapkan konsep Polymorphism.
  • 5. Polymorphism It is a mechanism which allows to have many forms of the method having the same name. (Polymorphism isthe ability of an object to take on many forms) The most common use of polymorphism inOOP occurs when a parent class referenceis used to refer to a child class object.
  • 6. Types of polym3 orphism in3/24/20 java There are two types of polymorphism in Java: Runtimepolymorphism(Dynamic polymorphism) Compiletimepolymorphism (Static polymorphism).
  • 7. Runtime Polymorphism (Dynamic polymorphism) Method overriding is a perfect example of runtime polymorphism. In this kind of polymorphism, reference of class Xcan hold object of class X or an object of any sub classes of class X. For e.g. if class Y extends class X then both ofthe following statements are valid: Y obj = new Y(); //Parent class reference can be assigned to child object X obj = new Y();
  • 8. Cont.., Since in method overriding both the classes(baseclass andchild class)havesamemethod,compile doesn’t figure out which method to call at compile-time. In this case JVM (Java Virtual Machine) decides which method tocall at runtime that’s why it is known as runtime or dynamic polymorphism.
  • 9. Example public class A { public void methodA() { //Base class method System.out.println("methodA of class A"); } } public class B extends A { public void methodA() { //Derived Class method System.out.println ("methodA of class B"); } } public class Z { public static void main (String args []) { A obj1 = new A(); // Reference and objectB A obj2 = new B(); // A reference but B object obj1.methodA(); obj2.methodA(); } Output: methodA of class A } Note:As you can see the methodA has different-2 forms in child and parent class thus we can say methodA here is polymorphic.
  • 10. Compile time Polymorphism (Static polymorphism) Compile time polymorphism is nothing but the method overloading in java. In simple terms we can say that a class can have more than one methods with same name but with different number of arguments or different types of arguments or both.
  • 11. Example class X { void methodA(int num) { System.out.println ("methodA: " + num); } void methodA(int n1, int n2) { System.out.println ("methodA: "+ n1 +“, "+ n2); } } public class Y { public static void main (String args []) { X Obj = new X(); double result; Obj. methodA(20); Obj. methodA(20, 30); Output: methodA: 20 } } Note: The class has 2 variance of methodA or we can say methodA is polymorphic in nature since it is having 2 different forms. In such scenario, compiler is able to figure out the method call at compile- time that’s the reason it is known as compile time pSoalymmpaothrpKhumisamrS.,AP