We are providing online training of realtime Live project on Asp.Net MVC with Angular and Web API. For more information click here. If you have any query then drop the messase in CONTACT FORM

Monday, June 22, 2015

1   Write a program to create ‘Square’ class with Area() method to calculate the Area of a Square. Create ‘Cube’ Class as derived class to Square class and override (using virtual, override keywords) the Area() method to calculate the Area of a Cube. Display the Area result on a Console application.
    
     class Program
    {
        public class Squre
        {
            public int side;
            public virtual int Area()
            {
                Console.WriteLine("Enter the side of the Squere:");
                side = int.Parse(Console.ReadLine());
                return side * side;
            }
        }
        public class Cube : Squre
        {
            public override int Area()
            {
                Console.WriteLine("Enter the side of the cube:");
                side = int.Parse(Console.ReadLine());
                return 6 * side * side;
            }
        }
        public class program
        {
            static void Main(string[] args)
            {
                Cube c = new Cube();
                Squre s = new Squre();
                Console.WriteLine("The Area of the cube:{0}", c.Area());
                Console.WriteLine();
                Console.WriteLine("The Area of the squer:{0}", s.Area());
                Console.ReadLine();
            }
        }

    }





No comments: