0

Draw an inheritance hierarchy for classes Quadrilateral, TRapezoid, Parallelogram, Rectangle and Square. Use Quadrilateral as the base class of the hierarchy. Make the hierarchy as deep as possible.

3
Contributors
2
Replies
60
Views
4 Years
Discussion Span
Last Post by james.lu.75491856
0

The trick is to use the is-a relationship. For example "a cat is a mammal" implies that class Cat is a subclass of class Mammal. In practice of course, there are other possible designs.

Edited by Gribouillis

0
class Quad(object):
class Par(Quad):
class Trap(Quad):
class Rect(Par):
class Square(Rect):

Par is a Quad
Trap is a Quad
Rect is a Quad
Square is a Quad
Rect is a Par
Square is a Par
Square is a Rect
Q->Par---->Rect-->Square
->Trap

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.