logo

APSU Notes


Quiz 3

Question 1

How is the inheritance relationship represented in a UML diagram?

By an arrow pointing from the derived class to the base class.

Question 2

Assume that Mammal is a subclass of Animal and Dog is a subclass of Mammal.

Given the following declarations:

1
2
3
Animal animal;
Mammal mammal;
Dog dog;

Which of the follow statements is not legal?

1
dog = animal;

Question 3

Given the following base case constructor definition:

1
2
3
4
public QuizQuestion(int initialPoints)
{
  points = initialPoints;
}

How would this constructor be called from a derived class constructor?

1
super(initialPoints);

Question 4

What is the difference between overriding a method and overloading a method?

A method in a derived class overrides a method with the same signature in the base class. A new method with a different signature but same name overloads an existing method in the same class.

Question 5

Given the following code:

1
2
3
4
5
6
7
8
9
10
public class Larry
{
  private Curly curly;
  /* additional instance variables and methods */
}

public class Moe extends Larry
{
  /* instance variables and methods */
}

Which of the following best describes the relationship between Larry, Curly, and Moe?

Larry has-a Curly. Moe is-a Larry.

Question 6

The keyword super can be used to call an overridden base class method in a method of the derived class.

True

Question 7

Why is it a good idea to override the toString and equals methods when creating a new class?

The inherited versions will not handle any private instance variables of the new class.

Question 8

Which of the following best describes the concept of inheritance?

A derived class inherits public methods from a base class.

Question 9

The Object class is the ultimate ancestor of every other class.

True

Question 10

What is the result if the final modifier is used in the heading of a method definition?

The method can not be overridden.

Question 11

A private method in a base class is inherited by a derived class.

False

Question 12

A method in a derived class with the same signature overrides the method from the base class.

True

Notes

Chapter 2/Inheritance