// Fig. 10.1: HierarchyRelationshipTest1.java // Assigning superclass and subclass references to superclass- and // subclass-type variables. import javax.swing.JOptionPane; public class HierarchyRelationshipTest1 { public static void main( String[] args ) { // assign superclass reference to superclass-type variable Point3 point = new Point3( 30, 50 ); // assign subclass reference to subclass-type variable Circle4 circle = new Circle4( 120, 89, 2.7 ); // invoke toString on superclass object using superclass variable String output = "Call Point3's toString with superclass" + " reference to superclass object: \n" + point.toString(); // invoke toString on subclass object using subclass variable output += "\n\nCall Circle4's toString with subclass" + " reference to subclass object: \n" + circle.toString(); // invoke toString on subclass object using superclass variable Point3 pointRef = circle; output += "\n\nCall Circle4's toString with superclass" + " reference to subclass object: \n" + pointRef.toString(); JOptionPane.showMessageDialog( null, output ); // display output System.exit( 0 ); } // end main } // end class HierarchyRelationshipTest1 /************************************************************************** * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and * * Prentice Hall. All Rights Reserved. * * * * DISCLAIMER: The authors and publisher of this book have used their * * best efforts in preparing the book. These efforts include the * * development, research, and testing of the theories and programs * * to determine their effectiveness. The authors and publisher make * * no warranty of any kind, expressed or implied, with regard to these * * programs or to the documentation contained in these books. The authors * * and publisher shall not be liable in any event for incidental or * * consequential damages in connection with, or arising out of, the * * furnishing, performance, or use of these programs. * *************************************************************************/