CSE143 – Miniquiz #4
01/23/2003
Name:
Section:
Directions: for each of the following questions, choose the ONE best answer.
Questions:
1) Suppose we have the following:
public class foo extends bar, foobar { ……
Which of the following is true? A.
a. foo should be an interface,bar and foobar need not, for
the expression to be legal.
b. foo should be a class, bar and foobar must be interfaces for the expression to be legal.
c. foo, bar and foobar must be interfaces for the expression to be legal.
d. The above statement is always illegal in Java as multiple inheritance is not supported.
2) A class Animal has a subclass Mammal. Which of the
following is true: B
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.
REMOVED FROM QUIZ:
3) A class Car and its subclass Yugo both have a method show() 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? (Hint: read ALL the choices before answering)
junker.show();
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 show() has been defined twice.
Optional question: to be discussed afterwards in Quiz Section:
4) What restriction is there on using super to invoke the constructor for a base class?
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.