revised: 10/05/03


on 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 a method's signature?

A.    The signature of a method is the name of the method the type of its return value.
B.    The signature of a method is the name of the method and the names of its parameters.
C.    The signature of a method is the name of the method and the data types of its parameters.
D.    The signature of a method is the name of the method, its parameter list, and its return type.

2. Here is a method definition:

int compute( a int, y double ){ . . . .}

Which of the following has a different signature?

A.    int compute( sum int, value double ){ . . . .}
B.    double compute( a int, y double ){ . . . .}
C.    double compute( sum int, y double ){ . . . .}
D.    int compute( a int, y int ){ . . . .}

3. What must a non-abstract child do about an abstract method in its parent class?

A.    A child must override an abstract method inherited from its parent by defining a method with the same signature and same return type.
B.    A child must define an additional method similar to the one inherited from its parent by defining a method with the same signature and different return type.
C.    A child must not define any method with the same signature as the parent's abstract method.
D.    A non-abstract child must define an abstract method with the same signature and same return type as the parent's abstract method.

4. Here is an abstract method defined in the parent:

public abstract int sumUp ( int[] arr );

Which of the following is required in a non-abstract child?

A.    public abstract int sumUp ( int[] arr ) { . . . }
B.    public int sumUp ( int[] arr ) { . . . }
C.    public double sumUp ( int[] arr ) { . . . }
D.    public int sumUp ( long[] arr ) { . . . }

5. What must be true if a child of an abstract parent class does not override all of the parent's abstract methods?

A.    This is always an error.
B.    The child class itself must be declared to be abstract.
C.    Child classes are automatically non-abstract, so this is OK.
D.    The parent class is in error.

6. Here is a situation:

Birthday happy;
happy = new AdultBirthday( "Joe", 39);

happy.greeting();

Which greeting() method is run: the one defined for Birthday or the one defined for AdultBirthday?

A.    The one defined for Birthday because that is the type of the variable happy.
B.    The one defined for AdultBirthday because that is the type of the object referred to by happy.
C.    The one closest in the source code to the happy.greeting() statement.
D.    Neither---the assignment statement is in error.

7. Say that class Rodent has a child class Rat and anothr child class Mouse. Class Mouse has a child class PocketMouse. Examine the following

Rodent rod;
Rat rat = new Rat();
Mouse mos = new Mouse();
PocketMouse pkt = new PocketMouse();

Which one of the following will cause a compiler error?

A.    rod = rat;
B.    rod = mos;
C.    pkt = null;
D.    pkt = rat;

8. Say that the situation is the same as in question 7. Which of the following array declarations is correct for an array that is expected to hold up to 10 objects of types Rat, Mouse, and PocketMouse?

A.    Rat[] array = new Rat[10];
B.    Rodent[] array = new Rat[10];
C.    Rodent[] array = new Rodent[10];
D.    Rodent[10] array;

9. What is the name of the class that is the ancestor to every other class in Java?

A.    Object
B.    Class
C.    Root
D.    Java

10. Examine the following code:

String str = "Hot Java";

boolean switch = str instanceof String;

What value is placed in switch?

A.    true
B.    false
C.    "Hot Java"
D.    null

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.