<<< Polymorphism | Index | Composition and Encapsulation >>> |
//A Very Simple Example class MainDriver { public static void main(String[] args) { System.out.println("The area is: "); Circle circle = new Circle(5); Rectangle rectangle = new Rectangle(4, 5); System.out.println( getArea( circle ) + getArea( rectangle ) ); } static double getArea( Shape shape ) { return shape.getArea(); } }
Any Shape-derived object we pass to getArea( ) java method of the MainDriver program will behave differently.
It depends on the type of shape which we pass as the parameter.
<<< Polymorphism | Index | Composition and Encapsulation >>> |