Answer to Question #327530 in C# for skillie

Question #327530

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.



1
Expert's answer
2022-04-12T16:16:00-0400
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);
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS