0% found this document useful (0 votes)
32 views2 pages

Homework2 COEN120

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.

Uploaded by

n
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views2 pages

Homework2 COEN120

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.

Uploaded by

n
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

SANTA CLARA UNIVERSITY

Computer Engineering Department


COEN 120 Real Time Systems

Homework 2 (Inheritance, Abstract Class, Interface)


(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.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy