//File: TwoClassDemo.java //Copy: Copyright (c) 1998, 2004 David Green //Vers: 1.1.1 20040916 dgg -- covnert names/style //Vers: 1.0.1 1998/10/16 dgg -- original coding public class TwoClassDemo { public static void main( String args[] ) { Rectangle rect; Square sq; Rectangle rectSq; System.out.println("TwoClassDemo"); rect = new Rectangle( 10, 20); sq = new Square( 5 ); rectSq = new Square( 2 ); System.out.println("direct invocation of area()" ); System.out.println("rect's area: " + rect.area() ); System.out.println("sq's area: " + sq.area() ); System.out.println("rectSq's area: " + rectSq.area() ); System.out.println("direct reference to printArea()'s"); rect.printArea(); sq.printArea(); rectSq.printArea(); System.out.println("parameter reference to printArea()'s" ); generalPrintArea( rect ); generalPrintArea( sq ); generalPrintArea( rectSq ); } public static void generalPrintArea( Rectangle aRect ) { /* Note: we will be calling the printArea of the object NOT * always the printArea() method of the Rectangle class */ aRect.printArea(); } }