Use polymorphism to find the area and perimeter of the rectangle and the area of the circle my perimeter
Shape shape = new Circle (5); New Square (5,6);
Double area = shape. Getarea ();
Double perimeter = shape. Getperimeter ();
Console.WriteLine ("The area of this shape is {0}, the perimeter is {1}", Area,perimeter);
Console.readkey ();
}
Public abstract class Shape
{
public abstract double Getarea ();
public abstract double getperimeter ();
}
public class Circle:shape
{
Private double _r;
Public double R
{
get {return _r;}
set {_r = value;}
}
Public Circle (Double R)
{
This. R = r;
}
public override double Getarea ()
{
Return Math.PI * this. R * this. R
}
public override double Getperimeter ()
{
Return 2*math.pi*this. R
}
}
public class Square:shape
{
Private double _height;
Public double Height
{
get {return _height;}
set {_height = value;}
}
Private double _width;
Public double Width
{
get {return _width;}
set {_width = value;}
}
Public Square (double height, double width)
{
This. Height = height;
This. width = width;
}
public override double Getarea ()
{
return this. Height * this. Width;
}
public override double Getperimeter ()
{
Return (this. Height+this. Width) * *;
}
}
Use polymorphism to find the area and perimeter of a rectangle and the area and perimeter of a circle