Question: Chapter 11: Dogs that Bark, or, Inheritance and Dynamic Dispatch For this lab you will create 3 classes: Dog, Lab, and Chi. (Lab and Chi

 Chapter 11: Dogs that Bark, or, Inheritance and Dynamic Dispatch For

Chapter 11: Dogs that Bark, or, Inheritance and Dynamic Dispatch For this lab you will create 3 classes: Dog, Lab, and Chi. ("Lab" and "Chi" are a lot shorter than "Labrador Retriever' and "Chihuahua," and also easier to spell.) Since Labradors and Chihuahuas are both kind of dogs, make Lab a subclass of Dog and Chi a subclass of Dog. In Dog define the method bark), which will print "Woof." Since Chihuahuas produce more of a high-pitched yip, override bark) in Chi to print "Yip!" instead of "Woof." Since Labradors bark like other dogs, don't override bark () in Lab. Create a main() method in Dog that creates a Lab and a Chi and puts them in an ArrayList of Dog. Use a for-each loop to iterate through your collection and send a Bark() message to each Dog. This should print: Woof. Yip

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!