[ Contact ] [ Links ] [ Previous : 3 / 29 : CG Example ] [ Up ] [ Next : 5 / 29 : Java Specifics : space and curly braces ]

Polymorphism

Polymorphism allows algorithms to be specified in terms of the most general (and/or reasonable) object type


void processShape(Shape s) 
	{
	s.setColor(Color.red);
 	// ... do stuff
	s.draw();
	}
         
Circle c = new Circle(x, y, r);
         
Point2D v1 = new Point2D(x1, y1);
Point2D v2 = new Point2D(x2, y2);
Point2D v3 = new Point2D(x3, y3);
Triangle t = new Triangle(v1, v2, v3);
         
Point2D c1 = new Point2D(u1, v1);
Point2D c2 = new Point2D(u2, v2);
Triangle r = new Rectangle(c1, c2);
         
processShape(c);
processShape(t);
processShape(r);

 




See the "Links" link above to find out the sources of the proposed informations
Pascal Vuylsteker / eScience / Computer Science / ANU
Last modified: 20/4/2004
TOC - Print
Send your comments at :
<Hugh.Fisher@anu.edu.au>