Wednesday, 20 November 2013

C# simple inheritance program to calculate area and volume of a room

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplicationinheritancettest
{
    public class room
    {
       public int length;
      public  int breadth;
        public room()
        {
            Console.WriteLine("enter length");
            length = int.Parse(Console.ReadLine());
            Console.WriteLine("enter breadth");
            breadth = int.Parse(Console.ReadLine());
        }


        public int area()
        {
            return (length * breadth);
        }
    }
    public class bedroom : room
    {
        int height;
        public bedroom()
            : base()
        {
            Console.WriteLine("enter height");
            height = int.Parse(Console.ReadLine());
        }
        public int volume()
        {
            return (length * breadth * height);
        }
    }
    class inheritancetest
    {
        public static void Main(string[] args)
        {
            bedroom room1 = new bedroom();
          int x= room1.area();
          Console.WriteLine("area" + x);
          int y=room1.volume();
          Console.WriteLine("volume" + y);
           
            Console.ReadKey();

        }
    }

Output:


}

No comments:

Post a Comment