# Another Quiz 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