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

Object-Oriented Polymorphism Unleashed
Object-Oriented Polymorphism UnleashedObject-Oriented Polymorphism Unleashed
Object-Oriented Polymorphism Unleashed
Naresh Chintalcheru
 
JAVA Polymorphism
JAVA PolymorphismJAVA Polymorphism
JAVA Polymorphism
Mahi Mca
 
Introduction to method overloading & method overriding in java hdm
Introduction to method overloading & method overriding  in java  hdmIntroduction to method overloading & method overriding  in java  hdm
Introduction to method overloading & method overriding in java hdm
Harshal Misalkar
 
Method Overloading In Java
Method Overloading In JavaMethod Overloading In Java
Method Overloading In Java
CharthaGaglani
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
Ahmed Za'anin
 
Polymorphism In Java
Polymorphism In JavaPolymorphism In Java
Polymorphism In Java
Spotle.ai
 
Polymorphism
PolymorphismPolymorphism
PolymorphismKumar
 
Polymorphism in java
Polymorphism in javaPolymorphism in java
Polymorphism in java
sureshraj43
 
Polymorphism in java
Polymorphism in java Polymorphism in java
Polymorphism in java
Janu Jahnavi
 
OOP - Polymorphism
OOP - PolymorphismOOP - Polymorphism
OOP - Polymorphism
Mudasir Qazi
 
Inheritance and Polymorphism Java
Inheritance and Polymorphism JavaInheritance and Polymorphism Java
Inheritance and Polymorphism Java
M. Raihan
 
Learn java lessons_online
Learn java lessons_onlineLearn java lessons_online
Learn java lessons_online
nishajj
 
Polymorphism in Python
Polymorphism in Python Polymorphism in Python
Polymorphism in Python
Home
 
polymorphism
polymorphism polymorphism
polymorphism
Imtiaz Hussain
 
Static and Dynamic polymorphism in C++
Static and Dynamic polymorphism in C++Static and Dynamic polymorphism in C++
Static and Dynamic polymorphism in C++
Anil Bapat
 
oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in java
CPD INDIA
 
28csharp
28csharp28csharp
28csharp
Sireesh K
 
Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...
Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...
Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...
cprogrammings
 

What's hot (20)

Object-Oriented Polymorphism Unleashed
Object-Oriented Polymorphism UnleashedObject-Oriented Polymorphism Unleashed
Object-Oriented Polymorphism Unleashed
 
JAVA Polymorphism
JAVA PolymorphismJAVA Polymorphism
JAVA Polymorphism
 
Introduction to method overloading & method overriding in java hdm
Introduction to method overloading & method overriding  in java  hdmIntroduction to method overloading & method overriding  in java  hdm
Introduction to method overloading & method overriding in java hdm
 
Method Overloading In Java
Method Overloading In JavaMethod Overloading In Java
Method Overloading In Java
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Polymorphism In Java
Polymorphism In JavaPolymorphism In Java
Polymorphism In Java
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Polymorphism in java
Polymorphism in javaPolymorphism in java
Polymorphism in java
 
Polymorphism in java
Polymorphism in java Polymorphism in java
Polymorphism in java
 
OOP - Polymorphism
OOP - PolymorphismOOP - Polymorphism
OOP - Polymorphism
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Inheritance and Polymorphism Java
Inheritance and Polymorphism JavaInheritance and Polymorphism Java
Inheritance and Polymorphism Java
 
Learn java lessons_online
Learn java lessons_onlineLearn java lessons_online
Learn java lessons_online
 
Polymorphism in Python
Polymorphism in Python Polymorphism in Python
Polymorphism in Python
 
OOP java
OOP javaOOP java
OOP java
 
polymorphism
polymorphism polymorphism
polymorphism
 
Static and Dynamic polymorphism in C++
Static and Dynamic polymorphism in C++Static and Dynamic polymorphism in C++
Static and Dynamic polymorphism in C++
 
oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in java
 
28csharp
28csharp28csharp
28csharp
 
Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...
Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...
Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...
 

Similar to P.7 media 2 polymorphism

polymorphismpresentation-160825122725.pdf
polymorphismpresentation-160825122725.pdfpolymorphismpresentation-160825122725.pdf
polymorphismpresentation-160825122725.pdf
BapanKar2
 
Java
JavaJava
‫‫Chapter4 Polymorphism
‫‫Chapter4 Polymorphism‫‫Chapter4 Polymorphism
‫‫Chapter4 Polymorphism
Mahmoud Alfarra
 
Polymorphism.pptx
Polymorphism.pptxPolymorphism.pptx
Polymorphism.pptx
RiturajJain8
 
polymorphism method overloading and overriding .pptx
polymorphism method overloading  and overriding .pptxpolymorphism method overloading  and overriding .pptx
polymorphism method overloading and overriding .pptx
thamaraiselvangts441
 
Java Polymorphism: Types And Examples (Geekster)
Java Polymorphism: Types And Examples (Geekster)Java Polymorphism: Types And Examples (Geekster)
Java Polymorphism: Types And Examples (Geekster)
Geekster
 
Object+oriented+programming+in+java
Object+oriented+programming+in+javaObject+oriented+programming+in+java
Object+oriented+programming+in+java
Ye Win
 
Chapter8:Understanding Polymorphism
Chapter8:Understanding PolymorphismChapter8:Understanding Polymorphism
Chapter8:Understanding Polymorphism
It Academy
 
28c
28c28c
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
 
Lecture 17
Lecture 17Lecture 17
Lecture 17
talha ijaz
 
Top 10 java oops interview questions
Top 10 java oops interview questionsTop 10 java oops interview questions
Top 10 java oops interview questions
nishajj
 
Top 10 java_oops_interview_questions
Top 10 java_oops_interview_questionsTop 10 java_oops_interview_questions
Top 10 java_oops_interview_questions
nishajj
 
Top 10 java oops interview questions
Top 10 java oops interview questionsTop 10 java oops interview questions
Top 10 java oops interview questions
nishajj
 
Top 10 java_oops_interview_questions
Top 10 java_oops_interview_questionsTop 10 java_oops_interview_questions
Top 10 java_oops_interview_questions
nishajj
 
Top 10 java_oops_interview_questions
Top 10 java_oops_interview_questionsTop 10 java_oops_interview_questions
Top 10 java_oops_interview_questions
nishajj
 
Top 10 java_oops_interview_questions
Top 10 java_oops_interview_questionsTop 10 java_oops_interview_questions
Top 10 java_oops_interview_questions
nishajj
 
Basics of oops concept
Basics of oops conceptBasics of oops concept
Basics of oops concept
DINESH KUMAR ARIVARASAN
 

Similar to P.7 media 2 polymorphism (20)

polymorphismpresentation-160825122725.pdf
polymorphismpresentation-160825122725.pdfpolymorphismpresentation-160825122725.pdf
polymorphismpresentation-160825122725.pdf
 
Java
JavaJava
Java
 
‫‫Chapter4 Polymorphism
‫‫Chapter4 Polymorphism‫‫Chapter4 Polymorphism
‫‫Chapter4 Polymorphism
 
Polymorphism.pptx
Polymorphism.pptxPolymorphism.pptx
Polymorphism.pptx
 
polymorphism method overloading and overriding .pptx
polymorphism method overloading  and overriding .pptxpolymorphism method overloading  and overriding .pptx
polymorphism method overloading and overriding .pptx
 
Java Polymorphism: Types And Examples (Geekster)
Java Polymorphism: Types And Examples (Geekster)Java Polymorphism: Types And Examples (Geekster)
Java Polymorphism: Types And Examples (Geekster)
 
Object+oriented+programming+in+java
Object+oriented+programming+in+javaObject+oriented+programming+in+java
Object+oriented+programming+in+java
 
Chapter8:Understanding Polymorphism
Chapter8:Understanding PolymorphismChapter8:Understanding Polymorphism
Chapter8:Understanding Polymorphism
 
28c
28c28c
28c
 
Chap11
Chap11Chap11
Chap11
 
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
 
Lecture 17
Lecture 17Lecture 17
Lecture 17
 
Top 10 java oops interview questions
Top 10 java oops interview questionsTop 10 java oops interview questions
Top 10 java oops interview questions
 
Top 10 java_oops_interview_questions
Top 10 java_oops_interview_questionsTop 10 java_oops_interview_questions
Top 10 java_oops_interview_questions
 
Top 10 java oops interview questions
Top 10 java oops interview questionsTop 10 java oops interview questions
Top 10 java oops interview questions
 
Top 10 java_oops_interview_questions
Top 10 java_oops_interview_questionsTop 10 java_oops_interview_questions
Top 10 java_oops_interview_questions
 
Top 10 java_oops_interview_questions
Top 10 java_oops_interview_questionsTop 10 java_oops_interview_questions
Top 10 java_oops_interview_questions
 
Top 10 java_oops_interview_questions
Top 10 java_oops_interview_questionsTop 10 java_oops_interview_questions
Top 10 java_oops_interview_questions
 
Basics of oops concept
Basics of oops conceptBasics of oops concept
Basics of oops concept
 

More from ahmadmuzaqqi

Virtual lan
Virtual lanVirtual lan
Virtual lan
ahmadmuzaqqi
 
Subnetting
SubnettingSubnetting
Subnetting
ahmadmuzaqqi
 
Model osi dan tcp
Model osi dan tcpModel osi dan tcp
Model osi dan tcp
ahmadmuzaqqi
 
Pengkabelan
PengkabelanPengkabelan
Pengkabelan
ahmadmuzaqqi
 
Routing
RoutingRouting
Routing
ahmadmuzaqqi
 
4 matriks dan relasi
4 matriks dan relasi4 matriks dan relasi
4 matriks dan relasi
ahmadmuzaqqi
 
Ppt modul 5 array
Ppt modul 5 arrayPpt modul 5 array
Ppt modul 5 array
ahmadmuzaqqi
 
Ppt modul 6 fungsi
Ppt modul 6 fungsiPpt modul 6 fungsi
Ppt modul 6 fungsi
ahmadmuzaqqi
 
Ppt modul 4 perulangan
Ppt modul 4 perulanganPpt modul 4 perulangan
Ppt modul 4 perulangan
ahmadmuzaqqi
 
Ppt modul 3 operasi kondisi
Ppt modul 3 operasi kondisiPpt modul 3 operasi kondisi
Ppt modul 3 operasi kondisi
ahmadmuzaqqi
 
Ppt modul 2 operator
Ppt modul 2 operatorPpt modul 2 operator
Ppt modul 2 operator
ahmadmuzaqqi
 
P.9 media 2 konsep inheritance
P.9 media 2 konsep inheritanceP.9 media 2 konsep inheritance
P.9 media 2 konsep inheritance
ahmadmuzaqqi
 
P.5 media 2 enkapsulasi
P.5 media 2 enkapsulasiP.5 media 2 enkapsulasi
P.5 media 2 enkapsulasi
ahmadmuzaqqi
 
P.3 media 2 class, objek, method pada java
P.3 media 2 class, objek, method pada javaP.3 media 2 class, objek, method pada java
P.3 media 2 class, objek, method pada java
ahmadmuzaqqi
 
Sejarah Java
Sejarah JavaSejarah Java
Sejarah Java
ahmadmuzaqqi
 

More from ahmadmuzaqqi (19)

Virtual lan
Virtual lanVirtual lan
Virtual lan
 
Subnetting
SubnettingSubnetting
Subnetting
 
Model osi dan tcp
Model osi dan tcpModel osi dan tcp
Model osi dan tcp
 
Pengkabelan
PengkabelanPengkabelan
Pengkabelan
 
Routing
RoutingRouting
Routing
 
5 fungsi
5 fungsi5 fungsi
5 fungsi
 
4 matriks dan relasi
4 matriks dan relasi4 matriks dan relasi
4 matriks dan relasi
 
3 himpunan
3 himpunan3 himpunan
3 himpunan
 
2 proposisi
2 proposisi2 proposisi
2 proposisi
 
1 logika
1 logika1 logika
1 logika
 
Ppt modul 5 array
Ppt modul 5 arrayPpt modul 5 array
Ppt modul 5 array
 
Ppt modul 6 fungsi
Ppt modul 6 fungsiPpt modul 6 fungsi
Ppt modul 6 fungsi
 
Ppt modul 4 perulangan
Ppt modul 4 perulanganPpt modul 4 perulangan
Ppt modul 4 perulangan
 
Ppt modul 3 operasi kondisi
Ppt modul 3 operasi kondisiPpt modul 3 operasi kondisi
Ppt modul 3 operasi kondisi
 
Ppt modul 2 operator
Ppt modul 2 operatorPpt modul 2 operator
Ppt modul 2 operator
 
P.9 media 2 konsep inheritance
P.9 media 2 konsep inheritanceP.9 media 2 konsep inheritance
P.9 media 2 konsep inheritance
 
P.5 media 2 enkapsulasi
P.5 media 2 enkapsulasiP.5 media 2 enkapsulasi
P.5 media 2 enkapsulasi
 
P.3 media 2 class, objek, method pada java
P.3 media 2 class, objek, method pada javaP.3 media 2 class, objek, method pada java
P.3 media 2 class, objek, method pada java
 
Sejarah Java
Sejarah JavaSejarah Java
Sejarah Java
 

Recently uploaded

Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 

Recently uploaded (20)

Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 

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