Solution: Create a Hierarchy of Inheritance
Look at the solution to the previous challenge.
We'll cover the following...
Problem statement
Explore inheritance hierarchies by following these steps:
Create a class named
Shapewith properties namedHeight,Width, andArea.Add three classes that derive from it:
Rectangle,Square, andCirclewith any additional members you feel are appropriate and that override and implement theAreaproperty correctly.In
Program.cs, add statements to create one instance of each shape, as shown in the following code:
Step-by-step solution
Let’s look at our solution by comprehensively understanding it.
Let’s have a look at Program.cs file:
In this file, we have created a new instances of Rectangle, Square, and Circle class with specific properties as follows:
The
Rectangleobject is constructed with specific values for itsheightandwidthproperties, which are3and4.5, respectively.The
Squareobject is constructed with a single value representing its side length; in this case, it’s set to5.The
Circleobject is constructed with a single value, ...