/* * @topic T10350 Feb 5, 2013 Inheritance Demo v.2 * @brief Main application class, InheritanceMain */ package inheritance; public class InheritanceMain { public static void main(String[] args) { // This array represents a virtual world of cats and dogs: VWCharacter[] characters = new VWCharacter[10]; int idx = 0; // Create some cats for ( ; idx < characters.length / 2; ++idx ) { characters[ idx ] = new Cat( "buddy" + ( idx + 1 ) ); } // Create some dogs idx = characters.length / 2; for ( ; idx < characters.length; ++idx ) { characters[ idx ] = new Dog( "barky" + ( idx + 1 ) ); } // Animate the world idx = 0; for ( ; idx < characters.length; ++idx ) { // This call demonstrates polymorphyc behavior of cats and dogs: characters[ idx ].speak(); // This call demonstrates that all classes in Java have toString() available: System.out.println( characters[ idx ].toString() ); // This does the same because println() calls toString() under the hood: System.out.println( characters[ idx ] ); } }//main }//InheritanceMain