Java Reference
In-Depth Information
EXERCISES
1. Mark the following statements as true or false.
a. The constructor of a subclass specifies a call to the constructor of the
superclass in the heading of the constructor's definition.
b. The constructor of a subclass specifies a call to the constructor of the
superclass using the name of the class.
c. A subclass must define a constructor.
d. In Java, polymorphism is implemented using late binding.
2. Draw a class hierarchy in which several classes are subclasses of a single
superclass.
Suppose that a class Employee is derived from the class Person (see
Example 8-8, in Chapter 8). Give examples of data and method members
that can be added to the class Employee .
3.
Identify the superclass and the subclass in each of the following pairs of classes.
a.
4.
d. BankAccount , SavingsAccount
e. GradStudent , Student
f. Dog , Animal
5. Draw the inheritance hierarchy diagram that shows the inheritance relation-
ship between the classes Person , Student , Employee , and Instructor .
6. Draw the inheritance hierarchy diagram that shows the inheritance relation-
ship between the classes Vehicle , Car , Sedan , Truck , PickupTruck ,
Object , and Animal .
7. Consider the following statement:
public class Dog extends Animal
{
Employee , Person
Vehicle , Truck
b.
Circle , Cylinder
c.
...
}
In this declaration, which class is the base class and which class is the derived class.
8. Consider the following class definitions:
class Circle
public class Cylinder extends Circle
{
{
private double radius;
private double height;
public Circle( double )
public Cylinder()
{
{
}
}
public Circle()
public Cylinder( double , double )
{
{
}
}
 
Search WWH ::




Custom Search