SlideShare a Scribd company logo
M.Rajshree
II-MSC(IT)
Nadar saraswathi college of arts&science
Polymorphism is the ability of a message to
be displayed in more than one form
 The most common use of polymorphism in
OOP occurs when a parent class reference is
used to refer to a child class object.
Any Java object that can pass more than one a
test is considered to be polymorphic
Create a completely separate class specific to
each type of object
These object classes would share a lot of
members in common, but they would be
completely separate from each other
for example, that had the generic object
members such as the speed property and the
travel method
There is another object oriented
Programming concept that is closely related
to abstract classes called interface
Interfaces allow us to define polymorphism
in a declarative way unrelated to
implementation
In interfaces, you can only define (not
implement) methods inside the parent class
Use the concept of an Interface class that will
define (but will not implement) common
properties and methods for the more specific
classes
Create separate classes then implement each
specific type of object that you will need
And that use the interface class to specify
common functionality
 The classes that implement the Interface must
implement all members of the Interface
 An Interface is a class that has only a method
body but no implementation
Example:
public interface shape
{
void draw();
}
Shape is an interface with only one method,
i.e. draw(). Basically, it is a contract that when
you are implementing that interface, you have
to implement the draw functionality, or else
you are not a complete class
 So for any class like Triangle or Rectangle,
when we implement that Interface, they must
implement the draw() method
 We sometimes use an arraylist, we are not as
concerned about how the feature set by the list
interface have been implemented by arraylist
Example :
List l = New ArrayList();
l.add()
 we needed to use an LinkedList instead of
an ArrayList, we could easily do that by changing:
List l = new LinkedList();
 ArrayList used in our program because we used
them through the contract published by the Interface
 The methods cannot be implemented inside the
interface
 Variables (properties) cannot be defined inside the
interface
 All the methods defined inside the interface need to
be implemented in the child class
 All the necessary variables need to be defined
inside the child class
 Man interface enforces its implementing classes to
implement all the methods in the interface
 Implementation interfaces, there are several
rules a class can implement more than
one interface at a time
A class can extend only one class but it
implement many interfaces
An interface can extend another interface in
a similar way as a class can extend another
class
Thank you

More Related Content

PDF
Interface
DOCX
C# concepts
PPTX
Abstract Class Presentation
PDF
Lecture 10
PPTX
Java interfaces
PPT
Core Java interview questions-ppt
DOC
116824015 java-j2 ee
Interface
C# concepts
Abstract Class Presentation
Lecture 10
Java interfaces
Core Java interview questions-ppt
116824015 java-j2 ee

What's hot (19)

PPTX
Lecture 18
PDF
Java OOP Programming language (Part 6) - Abstract Class & Interface
PPTX
PPTX
Top 20 c# interview Question and answers
DOCX
Java interface
PDF
Object Oriented Principles
DOCX
C# question answers
PPTX
Java presentation
PPT
Interface in java By Dheeraj Kumar Singh
PPT
Chapter 9 Interface
PPTX
Object Orinted Programing(OOP) concepts \
PPT
Chapter 03
PDF
Inheritance
PPTX
Interfaces in java
PDF
Data Structure Interview Questions & Answers
PPT
Interfaces
PPTX
Object Oriented Programming - Basic Concepts
PPTX
object oriented programing lecture 1
Lecture 18
Java OOP Programming language (Part 6) - Abstract Class & Interface
Top 20 c# interview Question and answers
Java interface
Object Oriented Principles
C# question answers
Java presentation
Interface in java By Dheeraj Kumar Singh
Chapter 9 Interface
Object Orinted Programing(OOP) concepts \
Chapter 03
Inheritance
Interfaces in java
Data Structure Interview Questions & Answers
Interfaces
Object Oriented Programming - Basic Concepts
object oriented programing lecture 1
Ad

Similar to Implementing polymorphism (20)

PPTX
Pi j3.2 polymorphism
PDF
‏‏‏‏‏‏oop lecture 6_١٢٥٩٤٧taiz univercity.pdf
PPT
Java interfaces
PPT
04 inheritance
PPT
Java interface
PPT
Polymorphism
DOCX
Corejavainterviewquestions.doc
PPTX
20.4 Java interfaces and abstraction
PPT
06 abstract-classes
PDF
L5
PPT
06 abstract-classes
PPTX
java_unitffjfjfjjrdteszserfdffvjyurt_6.pptx
PPTX
Interface in java
PPTX
Object Oriented Programming - Polymorphism and Interfaces
PPTX
Java session2
PPT
Inheritance in java.ppt
PDF
10_interfacesjavaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.pdf
PPTX
01. design pattern
PDF
javainterface
Pi j3.2 polymorphism
‏‏‏‏‏‏oop lecture 6_١٢٥٩٤٧taiz univercity.pdf
Java interfaces
04 inheritance
Java interface
Polymorphism
Corejavainterviewquestions.doc
20.4 Java interfaces and abstraction
06 abstract-classes
L5
06 abstract-classes
java_unitffjfjfjjrdteszserfdffvjyurt_6.pptx
Interface in java
Object Oriented Programming - Polymorphism and Interfaces
Java session2
Inheritance in java.ppt
10_interfacesjavaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.pdf
01. design pattern
javainterface
Ad

More from rajshreemuthiah (20)

PPTX
PPTX
PPTX
PPTX
polymorphism
PPTX
solutions and understanding text analytics
PPTX
interface
PPTX
Testing &ampdebugging
PPTX
concurrency control
PPTX
Education
PPTX
Formal verification
PPTX
Transaction management
PPTX
Multi thread
PPTX
System testing
PPTX
software maintenance
PPTX
exception handling
PPTX
e governance
PPTX
recovery management
PPSX
Buffer managements
PPTX
os linux
PPTX
polymorphism
solutions and understanding text analytics
interface
Testing &ampdebugging
concurrency control
Education
Formal verification
Transaction management
Multi thread
System testing
software maintenance
exception handling
e governance
recovery management
Buffer managements
os linux

Recently uploaded (20)

PDF
cuic standard and advanced reporting.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
A Presentation on Artificial Intelligence
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
Cloud computing and distributed systems.
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Electronic commerce courselecture one. Pdf
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Encapsulation theory and applications.pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
cuic standard and advanced reporting.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
Advanced methodologies resolving dimensionality complications for autism neur...
20250228 LYD VKU AI Blended-Learning.pptx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Understanding_Digital_Forensics_Presentation.pptx
A Presentation on Artificial Intelligence
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Cloud computing and distributed systems.
Dropbox Q2 2025 Financial Results & Investor Presentation
Per capita expenditure prediction using model stacking based on satellite ima...
Electronic commerce courselecture one. Pdf
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
NewMind AI Monthly Chronicles - July 2025
Encapsulation theory and applications.pdf
Encapsulation_ Review paper, used for researhc scholars
Review of recent advances in non-invasive hemoglobin estimation
“AI and Expert System Decision Support & Business Intelligence Systems”

Implementing polymorphism

  • 2. Polymorphism is the ability of a message to be displayed in more than one form  The most common use of polymorphism in OOP occurs when a parent class reference is used to refer to a child class object. Any Java object that can pass more than one a test is considered to be polymorphic
  • 3. Create a completely separate class specific to each type of object These object classes would share a lot of members in common, but they would be completely separate from each other for example, that had the generic object members such as the speed property and the travel method
  • 4. There is another object oriented Programming concept that is closely related to abstract classes called interface Interfaces allow us to define polymorphism in a declarative way unrelated to implementation In interfaces, you can only define (not implement) methods inside the parent class
  • 5. Use the concept of an Interface class that will define (but will not implement) common properties and methods for the more specific classes Create separate classes then implement each specific type of object that you will need And that use the interface class to specify common functionality
  • 6.  The classes that implement the Interface must implement all members of the Interface  An Interface is a class that has only a method body but no implementation Example: public interface shape { void draw(); }
  • 7. Shape is an interface with only one method, i.e. draw(). Basically, it is a contract that when you are implementing that interface, you have to implement the draw functionality, or else you are not a complete class  So for any class like Triangle or Rectangle, when we implement that Interface, they must implement the draw() method
  • 8.  We sometimes use an arraylist, we are not as concerned about how the feature set by the list interface have been implemented by arraylist Example : List l = New ArrayList(); l.add()  we needed to use an LinkedList instead of an ArrayList, we could easily do that by changing: List l = new LinkedList();  ArrayList used in our program because we used them through the contract published by the Interface
  • 9.  The methods cannot be implemented inside the interface  Variables (properties) cannot be defined inside the interface  All the methods defined inside the interface need to be implemented in the child class  All the necessary variables need to be defined inside the child class  Man interface enforces its implementing classes to implement all the methods in the interface
  • 10.  Implementation interfaces, there are several rules a class can implement more than one interface at a time A class can extend only one class but it implement many interfaces An interface can extend another interface in a similar way as a class can extend another class