SlideShare ist ein Scribd-Unternehmen logo
1 von 12
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

Weitere ähnliche Inhalte

Was ist angesagt?

Polymorphism
PolymorphismPolymorphism
Polymorphism
Kumar
 

Was ist angesagt? (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 |...
 

Ähnlich wie P.7 media 2 polymorphism

polymorphismpresentation-160825122725.pdf
polymorphismpresentation-160825122725.pdfpolymorphismpresentation-160825122725.pdf
polymorphismpresentation-160825122725.pdf
BapanKar2
 
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
 

Ähnlich wie 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
 

Mehr von 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
 

Kürzlich hochgeladen

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 

Kürzlich hochgeladen (20)

TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Role Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxRole Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptx
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
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 ...
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet 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
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 

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