Quiz on Inheritance

This is a practice quiz. The results are not recorded anywhere and do not affect your grade. The questions on this quiz might not appear in any quiz or test that does count toward your grade.

Instructions: For each question, choose the single best answer. Make your choice by clicking on its button. You can change your answers at any time. When the quiz is graded, the correct answers will appear in the box after each question.

1. What type of inheritance does Java have?

a. single inheritance
b. double inheritance
c. multiple inheritance
d. class inheritance

Correct Answer Is:

2. Say that there are three classes: Computer, AppleComputer, and IBMComputer. What are the likely relationships between these classes?

a. Computer is the superclass, AppleComputer and IBMComputer are subclasses of Computer.
b. IBMComputer is the superclass, AppleComputer and Computer are subclasses of IBMComputer.
c. Computer, AppleComputer and IBMComputer are sibling classes.
d. Computer is a superclass, AppleComputer is a subclasses of Computer, and IBMComputer is a subclass of AppleComputer

Correct Answer Is:

3. Can an object be a subclass of another object?

a. Yes—as long as single inheritance is followed.
b. No—inheritance is only between classes.
c. Only when one has been defined in terms of the other.
d. Yes—when one object is used in the constructor of another.

Correct Answer Is:

4. How many objects of a given class can there be in a program?

a. One per defined class.
b. One per constructor definition.
c. As many as the program needs.
d. One per main() method.

Correct Answer Is:

5. What restriction is there on using the super reference in a constructor?

a. It can only be used in the parent's constructor.
b. Only one child class can use it.
c. It must be used in the last statement of the constructor.
d. It must be used in the first statement of the constructor.

Correct Answer Is:

6. Which of the following is correct syntax for defining a new class Jolt based on the superclass SoftDrink?

a. class Jolt isa SoftDrink { //additional definitions go here }
b. class Jolt implements SoftDrink { //additional definitions go here }
c. class Jolt defines SoftDrink { //additional definitions go here }
d. class Jolt extends SoftDrink { //additional definitions go here }

Correct Answer Is:

7. A class Car and its subclass Yugo both have a method run() which was written by the programmer as part of the class definition. If junker refers to an object of type Yugo, what will the following code do?

a. The show() method defined in Yugo will be called.
b. The show() method defined in Car will be called.
c. The compiler will complain that run() has been defined twice.
d. Overloading will be used to pick which run() is called.

Correct Answer Is:

8. A class Animal has a subclass Mammal. Which of the following is true:

a. Because of single inheritance, Mammal can have no subclasses.
b. Because of single inheritance, Mammal can have no other parent than Animal.
c. Because of single inheritance, Animal can have only one subclass.
d. Because of single inheritance, Mammal can have no siblings.

Correct Answer Is:

9. Does a subclass inherit both member variables and methods?

a. No—only member variables are inherited.
b. No—only methods are inherited.
c. Yes—both are inherited.
d. Yes—but only one or the other are inherited.

Correct Answer Is:

10. Which of the following is NOT an advantage to using inheritance?

a. Code that is shared between classes needs to be written only once.
b. Similar classes can be made to behave consistently.
c. Enhancements to a base class will automatically be applied to derived classes.
d. One big superclass can be used instead of many little classes.

Correct Answer Is:

The number you got right:       Percent Correct:       Letter Grade:   

Click here (If you have just returned here from another page, or have re-loaded this page, you will need to click again on each of your choices for the grading program to work correctly. You may want to press the "shift key" while clicking on reload to clear the old answers.)