Java Reference
In-Depth Information
System.out.println(“Instantiating four dogs”);
Dog fido = new Dog();
Mammal rover = new Dog();
Play spot = new Dog();
Object pooch = new Dog();
System.out.println(“Invoking Dog methods”);
fido.sleep();
fido.playFetch();
fido.breathe();
System.out.println(“fido is “ + fido.toString());
System.out.println(“\nInvoking Mammal methods”);
rover.breathe();
System.out.println(“\nInvoking Play methods”);
spot.playCatch();
spot.playFetch();
System.out.println(“\nInvoking Object methods”);
System.out.println(“pooch is “ + pooch.toString());
((Dog) pooch).sleep();
}
}
Figure 10.11
The output of the FourDogs program.