Question: 1. Create a class hierarchy for clocks sold in a Clock Shop. This hierarchy should have 3 levels, with Clock at the top level. 2.Create
1. Create a class hierarchy for clocks sold in a "Clock Shop." This hierarchy should have 3 levels, with "Clock" at the top level.
2.Create a class for a generic clock and child classes extending the generic clock as required for your hierarchy (create further child classes from your child classes as needed).
3.Create the following public methods and set them at the appropriate places in the class hierarchy (we want to use inheritance). The Clock class (and perhaps some of its children) should be abstract. Thus, if you have no need to define a method at the top level(s), make the method abstract and override the methods as necessary
1.buyClock
2.sellClock
3.cleanClock
4.setClock
5.repairClock
4.Add at least one method that is unique to each child class.
5.Add code to each method that prints a message telling its function (e.g., "Cleaning Clock" or "Cleaning Grandfather Clock" and from which class/method it is being called (e.g., "called from class "Grandfather [extends Clock], method cleanClock".
6.Create instances of each non-abstract child object and invoke the methods common to all as well as the methods unique to each. Declare the data type of the object as Clock. For example:
Clock gClock = new GrandFatherClock(); Clock wClock = new Watch(); [other instantiations] . . . gClock.cleanClock(); wClock.cleanClock(); [all other methods for child classes] . . . ((GrandFatherClock)gClock).doGrandFatherStuff(); or GrandFatherClock g = (GrandFatherClock)gClock; g.doGrandFatherStuff(); [etc.] . . .
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
