creation: 7/17/99

Quiz on Abstract Classes and Polymorphism

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 is an abstract class?

a.    An abstract class is one without any child classes.
b.    An abstract class is any parent class with more than one child class.
c.    An abstract class is class which cannot be instantiated.
d.    abstract class is another name for "base class."

2. What is an abstract method?

a.    An abstract method is any method in an abstract class.
b.    An abstract method is a method which cannot be inherited.
c.    An abstract method is one without a body that is declared with the reserved word abstract.
d.    An abstract method is a method in the child class that overrids a parent method.

3. Can an abstract class define both abstract methods and non-abstract methods?

a.    No—it must have all one or the other.
b.    No—it must have all abstract methods.
c.    Yes—but the child classes do not inherit the abstract methods.
d.    Yes—the child classes inherit both.

4. Can an abstract parent class have non-abstract children?

a.    No—an abstract parent must have only abstract children.
b.    No—an abstract parent must have no children at all.
c.    Yes—all children of an abstract parent must be non-abstract.
d.    Yes—an abstract parent can have both abstract and non-abstract children.

5. Can an abstract method be defined in a non-abstract class?

a.    No—if a class defines an abstract method the class itself must be abstract.
b.    No—only classes are abstract, not methods.
c.    Yes—a method can be declared abstract in any parent as long as the child classes also declare it abstract.
d.    Yes—there is no restriction on where abstract methods can be defined.

6. Can an object of a child type be assigned to a variable of the parent type? For example,

Card crd;
BirthDay bd = new BirthDay("Lucinda", 42);

crd = bd;   //  is this correct?

a.    No—there must always be an exact match between the variable and the object types.
b.    No—but a object of parent type can be assigned to a variable of child type.
c.    Yes—an object can be assigned to a reference variable of the parent type.
d.    Yes—any object can be assigned to any reference variable.

7. What is polymorphism in Java?

a.    It is when a single variable is used with several different types of related objects at different places in a program.
b.    It is when a program uses several different types of objects, each with its own variable.
c.    It is when a single parent class has many child classes.
d.    It is when a class has several methods with the same name but different parameter types.

8. What determines what method is run in the following:

Card crd = new BirthDay("Lucinda", 42);

crd.greeting();

The type of the object or the type of the reference variable?

a.    The type of the object.
b.    The type of the reference variable.

9. In order for the following code to be correct, what must be the type of the reference variable card?

_________ card;

card = new Valentine( "Joe", 14 ) ;
card.greeting();

card = new Holiday( "Bob" ) ; 
card.greeting();

card = new Birthday( "Emily", 12 ) ; 
card.greeting();

a.    Valentine
b.    Holiday
c.    Birthday
d.    Card

10. What is an advantage of polymorphism?

a.    The same program logic can be used with objects of several related types.
b.    Variables can be re-used in order to save memory.
c.    Constructing new objects from old objects of a similar type saves time.
d.    Polymorphism is a dangerous aspect of inheritance and should be avoided.

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