Java Reference
In-Depth Information
tor of the superclass that has one parameter, of class
int
.
SR8.
private
.
SR9.
Yes, it can make sense. In implementing a class based on its specification, it may
be advantageous or necessary to add new methods for simplicity or readability
(or other reasons). These new methods are not mentioned in the specification and
should not be available to users of the class.
SR10.
Class
Object
.
SR11.
equals(Object)
and
toString()
.
SR12.
It should be an equivalence relation:
reflexive, symmetric, and transitive.
SR13.
If a B is a C, then B should be a sub-
class of C.
SR14.
False.
SR15.
A class invariant is a relation concerning the
fields of the class that should be true before and after each method of the class is
called. Essentially, the class invariant is given by the group of definitions of the
fields of the class.
SR16.
When determining the instance method to call (within
a folder) for a call
method-name
(
arguments
)
, start at the bottom of the folder
and search upward until the appropriate method is found.
Exercises for Chapter 4
E1.
Obtain classes
Employee
,
Executive
, and
HourlyEmployee
that are dis-
cussed in Sec. 4.1 from a footnote on Lesson page 4-1 of the CD. Design and
implement a fourth class,
SalariedEmployee
. An instance of this class repre-
sents an employee that is paid on a yearly basis; the employee gets no bonus and
no overtime.
E2.
Add a constructor to class
Employee
(and the other classes as well) of
Exercise E1 that initializes the hire date with the date at which an instance is cre-
ated. Thus, in
Employee
, this constructor has only one parameter, the name of the
person.
E3.
Design and implement a class
Manager
, which extends class
Salaried-
Employee
of Exercise E1. An instance should contain the name of the depart-
ment that the manager manages. You determine what extra methods are needed
and what function
toString
should produce.
E4.
Design and implement a class
Address
, which contains a house number,
street name, city, state, and zip code (for a house in the United States). Add a
field to class
Employee
of Exercise E1 to contain the address of an employee,
and add whatever methods are needed to make it accessible from outside the
class.
E5.
Suppose you are going to implement a set of classes that, together, describe
modes of transportation (e.g. plane, auto). Each of these modes has its own sub-
modes (e.g. an auto could be a car, SUV, truck, etc. Develop a hierarchy of such
modes of transportation, which would end up being a hierarchy of classes and
subclasses. This is an open-ended question, and there is no single answer.
E6.
Turn to lesson page 4-1 on the
ProgramLive
CD and click on “Proj”. A win-
dow opens, with some projects in it. Carry out project “Movie reviews”.
Search WWH ::
Custom Search