"Polymorphic" means "many forms." In Java, you can have a superclass with subclasses that do different things using the same name. A traditional example is the Shape superclass with subclasses of Circle , Square and Rectangle and the area() method.
So for example
// note code is abbreviated, this is just for explanation class Shape { public int area(); // no implementation, this is abstract } class Circle { private int radius; public Circle(int r){ radius = r ; } public int area(){ return Math.PI*radius*radius ; } } class Square { private int wid; Public Square(int w){ wid=w; } public int area() { return wid*wid; } }
Now consider an example
Shape s[] = new Shape[2]; s[0] = new Circle(10); s[1] = new Square(10); System.out.println("Area of s[0] "+s[0].area()); System.out.println("Area of s[1] "+s[1].area());
s[0].area() calls Circle.area() , s[1].area() calls Square.area() - and therefore we say that Shape and its subclasses use polymorphic calls in the method area.
Charlie martin
source share