How is the inheritance relationship represented in a UML diagram?
By an arrow pointing from the derived class to the base class.
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;
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);
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.
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.
The keyword super
can be used to call an overridden base class method in a method of the derived class.
True
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.
Which of the following best describes the concept of inheritance?
A derived class inherits public methods from a base class.
The Object
class is the ultimate ancestor of every other class.
True
What is the result if the final
modifier is used in the heading of a method definition?
The method can not be overridden.
A private method in a base class is inherited by a derived class.
False
A method in a derived class with the same signature overrides the method from the base class.
True