0% found this document useful (0 votes)
47 views2 pages

Understanding Polymorphism in Java

Polymorphism refers to the ability of a reference variable to change behavior based on the object instance it holds, allowing different subclasses to be treated as a single superclass. In Java, this enables methods to be defined for various derived classes, such as circles and rectangles, while ensuring the correct method is applied based on the object's subclass. An example is the area method in a base class shape, which returns the appropriate result for any derived shape object.

Uploaded by

pankaj
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views2 pages

Understanding Polymorphism in Java

Polymorphism refers to the ability of a reference variable to change behavior based on the object instance it holds, allowing different subclasses to be treated as a single superclass. In Java, this enables methods to be defined for various derived classes, such as circles and rectangles, while ensuring the correct method is applied based on the object's subclass. An example is the area method in a base class shape, which returns the appropriate result for any derived shape object.

Uploaded by

pankaj
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Polymorphism

1. Agenda What is and Why Polymorphism?


● Examples of Polymorphism in Java
programs ● 3 forms of Polymorphism ● 2
2. What is & Why Polymorphism? 3
3. What is Polymorphism? Generally,
polymorphism refers to the ability to ●
appear in many forms Polymorphism in a
Java program ● The ability of a reference
variable to change – behavior according to
what object instance it is holding. This allows
multiple objects of different subclasses – to be
treated as objects of a single super class,
while automatically selecting the proper
methods to apply to a particular object based
on the subclass it belongs to 4
4. Polymorphism Example For example,
given a base class shape, ● polymorphism
enables the programmer to define different
area methods for any number of derived
classes, such as circles, rectangles and
triangles. No matter what shape an object is,
applying the ● area method to it will return
the correct results.

You might also like