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.
Evan has probably moved on to other problems in the four years since he posted this question
vivek kumar jaiswal wrote:Hi Evan check this code it's running as your requirement
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