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.

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.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.