QMCS 280, Spring 1998
Exam 3
Name: _________________________________ Date: _____________________
1. Briefly describe (in your own words, not copied from the book) what "inheritance" is in object oriented programming.
2. Circle the correct answer. Which of the following terms is used to describe the class from which another class inherits:
a. parent class
b. super class
c. base class
d. all of the above
3. Fill in the blank. Inheritance represents a type of relationship that we've been labeling ________________________ as opposed to a relationship that is "has a".
4. Circle the correct answer. Which of the following is the proper Java syntax for a class called "Sedan" to inherit from a class called "Automobile"?
a. class Automobile implements Sedan {
b. class Sedan implements Automobile {
c. class Automobile extends Sedan {
d. class Sedan extends Automobile {
5. Briefly explain (in your own words) what it means to say that Java allows single inheritance only.
6. Sketch a module diagram that shows the class Commercial_Building inheriting from Building, Private_Building inheriting from Building, Bank inheriting from Commericial_Building, and Restaurant inheriting from Commercial_Building.
7. Write the Java code necessary to fully define two classes -- "Building" and "Commercial_Building". Building has variables for the length, width, and height of the building and it has a method to print out these dimensions. Commercial_Building will inherit all the methods and variables from Building and will also store away a string describing the purpose of the building. Commericial_Building will supplement the print method of Building by also printing the purpose. Don't forget constructors for these classes!
8. Circle the correct answer. Which of the following visibility modifiers will allow a variable to be inherited, but will not allow the variable to be seen by any class that does not inherit from it?
a. private
b. protected
c. public
d. none of the above
9. Briefly describe what is meant by saying that inheritance is "one way only".
10. Briefly describe what is meant by "overriding" in object oriented programming.
11. Circle the correct answer. Which of the following terms describes the situation whereby the code to invoke a method may, in fact, invoke one method at one time and another method at another time.
a. inheritance
b. polymorphism
c. overriding
d. abstract method
12. Write the Java code necessary to fully define three classes. The "Automobile" class has a variable for horsepower of the engine and a variable for color. It also has a print method to print these values and it has a cost method to return the value "horsepower times 100". The second class is "Sedan" which has a variable for the number of doors and will override the print method of the Automobile class. The third class is "Coup" which has a variable for the number of doors and overrides the print method of the Automobile class. Both Sedan and Coup will inherit the methods but not the variables of the Automobile class.
13. Circle the correct answer. Which of the following is a characteristic of an abstract class?
a. It has at least one abstract method
b. It cannot be instantiated
c. It must have child classes
d. All of the above
e. None of the above
14. Briefly explain why abstract methods cannot be declared as "final" or "static".
15. Indicate what errors there are in the Java code below by circling the erroneous code and then describing the error below the code.
class Drugs {
protected String name;
private double cost;
Drugs(String id, int price){
name = id;
price = cost;
}
abstract private print();
}
class Morphine extends Drugs{
private double dosage;
Morphine(String id, int price, double howMuch){
Drugs(id, price, howMuch);
dosage = howMuch;
}
}
16. Circle all the correct choices. Which of the following are true of "interfaces" in Java?
a. They are just the same as classes
b. They are Java's way of allowing multiple inheritance
c. They contain constants and abstract methods only
d. Classes that implement an interface must fully define the abstract methods
e. Classes can only implement one interface
f. None of the above
17. Write the Java code needed to define the following interface. The interface name is "Grade_Report". It has five constants for the value of grades A, B, C, D, and F. It has a method for calculating and returning the grade point average and a method for printing the grade report and returning nothing.
18. Briefly describe the advantages and uses of the combination of abstract classes and interfaces in Java.
19. Briefly describe the purpose of "packages" in Java.
20. Briefly describe what the three components of the "GUI program model" are, as presented in your text.
21. Fill in the blank. A GUI component that represents a set of options a user can choose, located at the top of a window is called a _________________________________.
22. Fill in the blank. A GUI event that is generated by selecting an item from a list or group is called a ________________________ event.
23. Fill in the blank. A GUI component that allows entry of text information on one line is called a ______________________________.
24. Fill in the blank. A GUI layout manager that lays components out in a north, south, east, west, and center pattern is called the ______________________________ layout manager.
25. Fill in the blank. A "listener" that listens for actions on a Button, List, TextField, or MenuItem component is called the _______________________ listener.