...

/

Solution Review: Implement and Override the Method

Solution Review: Implement and Override the Method

This review provides a detailed analysis on how to solve the 'Implement and Override the Method' challenge.

We'll cover the following...

Solution

Press + to interact
// Base Class
class Shape {
public Shape() {} // Default Constructor
// Getter Function
public virtual double ClacArea() {
return 0;
}
}
// Derived Class
class Circle : Shape {
private double _radius;
public Circle(double radius) { // Constructor
this._radius = radius;
}
// Overridden CalcArea() method which returns the area of Rectangle
public override double ClacArea() {
return (this._radius * this._radius) * 3.14;
}
}
class Demo {
public static void Main(string[] args) {
Shape circle = new Circle(2);
Console.WriteLine(circle.ClacArea());
}
}

Explanation

The ...