SlideShare a Scribd company logo
1 of 7
Polymorphism
In JAVA
-M Vishnuvardhan,
Dept. of Computer Science,
SSBN Degree College, ATP
SSBN Degree College, ATP M Vishnuvardhan
Introduction
Polymorphism is a Greek word which
means one name multiple forms (Ploy –
many & morphism – forms). There are two
type of Polymorphisms.
 Compile Time Polymorphism ( Method
Overloading )
 Run Time Polymorphism. ( Method Overriding )
SSBN Degree College, ATP M Vishnuvardhan
Method Overloading
Declaring multiple methods with same
name in a class is called Method overloading
or compile time polymorphism.
Eg:
class A
{
======
void process()
{ --- }
void process( --- )
{--- }
=====
}
Method
overloading
SSBN Degree College, ATP M Vishnuvardhan
Rules for Overloading
To overload multiple methods in java any two methods
must satisfy any of the following conditions. Other wise
those methods are not considered as overloaded and also
compile time error is generated
There must be difference number of parameters (OR)
There must be difference in type of parameters
Valid examples
int add(int a, int b) { }
int add(int a, int b, int c) { }
int add(float a, float b) { }
Invalid examples
int add(int a, int b) { }
int add(int x, int y) { }
float add(int a, int b) { }
SSBN Degree College, ATP M Vishnuvardhan
Compiler in Action
When ever a method is invoked the java compiler decides and
calls the appropriate method basing on the no of parameters
or the type of parameters. If any two methods have same
signature then ambiguity arises.
int add(int a, int b) { }
int add(int a, int b, int c) { }
int add(float a, float b) { }
Note: return type doesn’t help in deciding the function
int add(int x, int y) { }
float add(int a, int b) { }
add(10,25)
add(10,25,35)
add(25.45,51.20)
add(10,25)
add(10,25)
SSBN Degree College, ATP M Vishnuvardhan
Questions
SSBN Degree College, ATP M Vishnuvardhan
Questions

More Related Content

What's hot (10)

Polymorphism in java
Polymorphism in java Polymorphism in java
Polymorphism in java
 
polymorphism ppt
polymorphism pptpolymorphism ppt
polymorphism ppt
 
Polymorphism in java
Polymorphism in javaPolymorphism in java
Polymorphism in java
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
P.7 media 2 polymorphism
P.7 media 2 polymorphismP.7 media 2 polymorphism
P.7 media 2 polymorphism
 
Method in oop
Method in oopMethod in oop
Method in oop
 
Polymorphism In Java
Polymorphism In JavaPolymorphism In Java
Polymorphism In Java
 
Copy propagation
Copy propagationCopy propagation
Copy propagation
 
Bt0074
Bt0074Bt0074
Bt0074
 

Similar to Polymorphism

Www javatpoint-com-corejava-interview-questions-2
Www javatpoint-com-corejava-interview-questions-2Www javatpoint-com-corejava-interview-questions-2
Www javatpoint-com-corejava-interview-questions-2
ssuserd2d58b
 

Similar to Polymorphism (15)

JAVA_POLYMORPHISM.pptx
JAVA_POLYMORPHISM.pptxJAVA_POLYMORPHISM.pptx
JAVA_POLYMORPHISM.pptx
 
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
 
Overloading and overriding in vb.net
Overloading and overriding in vb.netOverloading and overriding in vb.net
Overloading and overriding in vb.net
 
Unit 2 Part 1 POLYMORPHISM.pdf
Unit 2 Part 1 POLYMORPHISM.pdfUnit 2 Part 1 POLYMORPHISM.pdf
Unit 2 Part 1 POLYMORPHISM.pdf
 
polymorphism method overloading and overriding .pptx
polymorphism method overloading  and overriding .pptxpolymorphism method overloading  and overriding .pptx
polymorphism method overloading and overriding .pptx
 
Www javatpoint-com-corejava-interview-questions-2
Www javatpoint-com-corejava-interview-questions-2Www javatpoint-com-corejava-interview-questions-2
Www javatpoint-com-corejava-interview-questions-2
 
Java Inheritance and Polymorphism
Java Inheritance and PolymorphismJava Inheritance and Polymorphism
Java Inheritance and Polymorphism
 
Learn java lessons_online
Learn java lessons_onlineLearn java lessons_online
Learn java lessons_online
 
Method Overloading in Java
Method Overloading in JavaMethod Overloading in Java
Method Overloading in Java
 
Java Polymorphism: Types And Examples (Geekster)
Java Polymorphism: Types And Examples (Geekster)Java Polymorphism: Types And Examples (Geekster)
Java Polymorphism: Types And Examples (Geekster)
 
Method overloading
Method overloadingMethod overloading
Method overloading
 
Overloading vs Overriding.pptx
Overloading vs Overriding.pptxOverloading vs Overriding.pptx
Overloading vs Overriding.pptx
 
Basics of Java
Basics of JavaBasics of Java
Basics of Java
 
Lecture 6 inheritance
Lecture   6 inheritanceLecture   6 inheritance
Lecture 6 inheritance
 
Polymorphism in Java
Polymorphism in JavaPolymorphism in Java
Polymorphism in Java
 

More from M Vishnuvardhan Reddy

More from M Vishnuvardhan Reddy (20)

Python Sets_Dictionary.pptx
Python Sets_Dictionary.pptxPython Sets_Dictionary.pptx
Python Sets_Dictionary.pptx
 
Lists_tuples.pptx
Lists_tuples.pptxLists_tuples.pptx
Lists_tuples.pptx
 
Python Control Structures.pptx
Python Control Structures.pptxPython Control Structures.pptx
Python Control Structures.pptx
 
Python Strings.pptx
Python Strings.pptxPython Strings.pptx
Python Strings.pptx
 
Python Basics.pptx
Python Basics.pptxPython Basics.pptx
Python Basics.pptx
 
Python Operators.pptx
Python Operators.pptxPython Operators.pptx
Python Operators.pptx
 
Python Datatypes.pptx
Python Datatypes.pptxPython Datatypes.pptx
Python Datatypes.pptx
 
DataScience.pptx
DataScience.pptxDataScience.pptx
DataScience.pptx
 
Html forms
Html formsHtml forms
Html forms
 
Cascading Style Sheets
Cascading Style SheetsCascading Style Sheets
Cascading Style Sheets
 
Java Threads
Java ThreadsJava Threads
Java Threads
 
Java Streams
Java StreamsJava Streams
Java Streams
 
Scanner class
Scanner classScanner class
Scanner class
 
Java intro
Java introJava intro
Java intro
 
Java applets
Java appletsJava applets
Java applets
 
Exception handling
Exception handling Exception handling
Exception handling
 
Control structures
Control structuresControl structures
Control structures
 
Constructors
ConstructorsConstructors
Constructors
 
Classes&objects
Classes&objectsClasses&objects
Classes&objects
 
Shell sort
Shell sortShell sort
Shell sort
 

Recently uploaded

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 

Recently uploaded (20)

Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 

Polymorphism

  • 1. Polymorphism In JAVA -M Vishnuvardhan, Dept. of Computer Science, SSBN Degree College, ATP
  • 2. SSBN Degree College, ATP M Vishnuvardhan Introduction Polymorphism is a Greek word which means one name multiple forms (Ploy – many & morphism – forms). There are two type of Polymorphisms.  Compile Time Polymorphism ( Method Overloading )  Run Time Polymorphism. ( Method Overriding )
  • 3. SSBN Degree College, ATP M Vishnuvardhan Method Overloading Declaring multiple methods with same name in a class is called Method overloading or compile time polymorphism. Eg: class A { ====== void process() { --- } void process( --- ) {--- } ===== } Method overloading
  • 4. SSBN Degree College, ATP M Vishnuvardhan Rules for Overloading To overload multiple methods in java any two methods must satisfy any of the following conditions. Other wise those methods are not considered as overloaded and also compile time error is generated There must be difference number of parameters (OR) There must be difference in type of parameters Valid examples int add(int a, int b) { } int add(int a, int b, int c) { } int add(float a, float b) { } Invalid examples int add(int a, int b) { } int add(int x, int y) { } float add(int a, int b) { }
  • 5. SSBN Degree College, ATP M Vishnuvardhan Compiler in Action When ever a method is invoked the java compiler decides and calls the appropriate method basing on the no of parameters or the type of parameters. If any two methods have same signature then ambiguity arises. int add(int a, int b) { } int add(int a, int b, int c) { } int add(float a, float b) { } Note: return type doesn’t help in deciding the function int add(int x, int y) { } float add(int a, int b) { } add(10,25) add(10,25,35) add(25.45,51.20) add(10,25) add(10,25)
  • 6. SSBN Degree College, ATP M Vishnuvardhan Questions
  • 7. SSBN Degree College, ATP M Vishnuvardhan Questions