This document provides instructions for 5 homework problems related to inheritance, abstract classes, and interfaces in Java. The problems involve:
1. Explaining the difference between abstract classes and interfaces.
2. Creating classes for different types of rodents that extend an abstract Rodent class.
3. Creating an abstract class without abstract methods.
4. Modifying the Rodent class to be abstract and make its methods abstract.
5. Writing an Instrument interface with two methods, and classes that implement the interface to print messages when the methods are called.
This document provides instructions for 5 homework problems related to inheritance, abstract classes, and interfaces in Java. The problems involve:
1. Explaining the difference between abstract classes and interfaces.
2. Creating classes for different types of rodents that extend an abstract Rodent class.
3. Creating an abstract class without abstract methods.
4. Modifying the Rodent class to be abstract and make its methods abstract.
5. Writing an Instrument interface with two methods, and classes that implement the interface to print messages when the methods are called.
This document provides instructions for 5 homework problems related to inheritance, abstract classes, and interfaces in Java. The problems involve:
1. Explaining the difference between abstract classes and interfaces.
2. Creating classes for different types of rodents that extend an abstract Rodent class.
3. Creating an abstract class without abstract methods.
4. Modifying the Rodent class to be abstract and make its methods abstract.
5. Writing an Instrument interface with two methods, and classes that implement the interface to print messages when the methods are called.
(15 points) For each of the following programs, compile and execute the program and submit the code as well as the output. Programs must contain comments and should use an appropriate indentation style. 1. What is the difference between an abstract class and an interface? 2. Create three classes Mouse, Gerbil and Hamster that have a common superclass called Rodent. In the base class Rodent, provide methods that are common to all rodents, and override these in the derived classes to perform different types of behaviors depending on the specific type of Rodent. Create an array of Rodent, fill it with different specific types of Rodents, and call your base class methods to see what happens. 3. Create a class as abstract without including any abstract methods, and verify that you cannot create an instance of that class. 4. Modify the Rodent class in Example 1 so that it is an abstract class. Make the methods of Rodent abstract whenever possible. 5. (a) Write an interface calls Instrument with two methods: void play(String notes); void adjust(); (b) Write two classes called Wind and Percussion that implement this interface. The method body contains a print statement to display a message containing the name of the class and the method name on the screen. (c) Write a class called Brass that extends Wind and does not define any methods. (d) Write a class called Woodwind that extends Wind and does not define any methods.
(e) Write a new class called Music that contains a main method. In main, create an instance of the Brass, Woodwind and Percussion classes. Each instance calls its play method.