created: 07/17/99; revised: 10/05/03


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 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 to clear the old answers.