 |
|
Lab 6
Objective
To introduce inheritance
Classwork:
-
Imagine a publishing company that markets both
book and audiocassette versions of its works. Create a class Publication
that stores the title ( type String ) and price ( type
float ) of a publication. From this class derive two classes: Book,
which adds pages count ( type int ); and Tape, which adds a
playing time in minutes ( type float ). Each of these three classes should
have get and set functions. Also they
should have an overridden function toString to display the data.
Write an application TestInheritance to test the Book and Tape
classes by creating instances of them, and displaying there data. Use an
instance of class DecimalFormat to format any float number to be
displayed with two digits to the right of the decimal point. The figure bellow
show a sample output:

|
|
|