Polymorphism
Introduction
Polymorphism

Example in Biology:
– Different ‘forms’, same species
Light-morph jaguar
Dark-morph or black or
melanistic jaguar
Adapted and adopted from Deitel (2004), IBM (2004), Liang (2007),
Oracle (2012), and Wikipedia
Polymorphism

Example in Biology:
– Different ‘forms’ between males and females of the
same species
Adapted and adopted from Deitel (2004), IBM (2004), Liang (2007),
Oracle (2012), and Wikipedia
Polymorphism

In Java OOP:
– Subclasses of a class can define their own unique
behaviors and yet share some of the same
functionality of the parent class.
Adapted and adopted from Deitel (2004), IBM (2004), Liang (2007),
Oracle (2012), and Wikipedia
Polymorphism
public class CylinderDemo {
public static void main(String[] args) {
Shape shape;
shape = new Shape();
System.out.println("Area of current shape: " + shape.getArea());
shape = null;
shape = new Circle(10);
System.out.println("Area of current shape: " + shape.getArea());
shape = null;
shape = new Cylinder(11, 21);
System.out.println(" Area of current shape: " + shape.getArea());
shape = null;
}
}
Adapted and adopted from Deitel (2004), IBM (2004), Liang (2007),
Oracle (2012), and Wikipedia
References







Oracle. The Java Tutorials. [Online]. http://docs.oracle.com/javase/tutorial/
Oracle. Java SE Tutorial 2012-02-28 [Online].
http://www.oracle.com/technetwork/java/javase/downloads/java-se-7tutorial-2012-02-28-1536013.html
Oracle. Java SE Downloads [Online].
http://www.oracle.com/technetwork/java/javase/downloads/index.html
Harvey M. Deitel and Paul J. Deitel, Java: How to Program, 6th ed.: Prentice
Hall, 2004.
Ken Arnold, James Gosling, and David Holmes, The Java Programming
Language, 4th ed.: Addison Wesley Professional, 2005.
Sharon Zakhour, Scott Hommel, Jacob Royal, Isaac Rabinovitch, and Tom
Risser, The Java Tutorial Fourth Edition: A Short Course on the Basics, 4th ed.:
Addison Wesley Professional, 2006.
Y. Daniel Liang, Introduction to Java Programming, 6th ed.: Pearson Prentice
Hall, 2007.
Adapted and adopted from Deitel (2004), IBM (2004), Liang (2007),
Oracle (2012), and Wikipedia
References


Wikipedia. Sexual dimorphism. [Online].
http://en.wikipedia.org/wiki/Sexual_dimorphism
Wikipedia. Polymorphism (biology). [Online].
http://en.wikipedia.org/wiki/Polymorphism_(biology)
Adapted and adopted from Deitel (2004), IBM (2004), Liang (2007),
Oracle (2012), and Wikipedia