Create a C# console application that prints the Area of a square.
The application must use OOP concepts:
Create an abstract class named ShapesClass.
ShapesClass must contain an abstract method named Area.
Create a class named Square that inherits from ShapesClass.
Square class must contain a Square method.
Create a method named Area that will override abstract method Area, and then return the sides of the square.
In the main method create an object of the square class, with the value of the side. Print the Area of the square.
using System;
namespace abstract_class
{
abstract class ShapesClass
{
public abstract int Area();
}
class Square : ShapesClass
{
private int side;
public Square(int n)
{
side = n;
}
public override int Area()
{
return side * side;
}
}
class Program
{
public static void Main(string[] args)
{
Square square = new Square(5);
Console.WriteLine("Area of the square = {0}", square.Area());
Console.Write("\nPress any key to continue . . . ");
Console.ReadKey(true);
}
}
}
Comments
Leave a comment