Create a base class named "Rectangle" that contains length and width data members. From this class, derive a class named "Box" having an additional data memner named "depth". The method members of the base "Rectangle" class should consist of a constructor and an override method named "area()" method. The derived "Box" class should have a constructor and an override method named "area()" that retuns the surface area od the box and a "volume()" method.
Include in the classes constructed for the previous exercise in a working Java program. Have yoru program call all of the member methods in each class and explain the result when the area method is called using the two "box" objects.
Originally posted by Campbell Ritchie:
I hope you never extend Rectangle to create Box when you have finished this course, because Rectangle and Box cannot have an "is-a" relationship with each other.
Joanne
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Evan has probably moved on to other problems in the four years since he posted this questionvivek kumar jaiswal wrote:Hi Evan check this code it's running as your requirement
Joanne
Not until you Show Some Effort we can'tLizunga Lopez wrote:But you can still help me with this exercise!!!
Joanne
So you have. You need to consider your class design. Get a pencil and paper and draw the inheritance hierarchy. Also draw a Vehicle. Make sure you know what it looks like.Lizunga Lopez wrote: . . . and my prof says i still have errors :/
:s
Campbell Ritchie wrote:[Nasty pedantic mode]"Base" and "derive" are not Java terms; they are what one says in C#. He means "superclass" and "extend" or "create a subclass of."
Lizunga wrote: i am not sure if I need another if statement for the methods unlock and lock
My name is Inigo Montoya, you killed my father, prepare to read a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
|