I am wondering, as to why I am not getting an error in the code below. I have defined no constructors in the base class, but have defined one in the derived class. Still the code runs as expected. Can someone kindly help me to get rid of the confusion.
class Shape
{
public void Area()
{
Console.WriteLine("I am a shape");
}
}
class Circle : Shape
{
double radius;
const double pi = 3.14;
public Circle(double rad)
{
radius = rad;
}
public new double Area()
{
return pi * radius * radius;
}
}
The code compiles perfectly and gives me the desired results. Thank you,
class Progam
{
static void Main(string[] args)
{
Shape s1 = new Shape();
s1.Area();
Shape s2 = new Circle(10);
s2.Area();
Circle c1 = new Circle(4.0);
Console.WriteLine(c1.Area());
}
}