Loading, please wait...

A to Z Full Forms and Acronyms

Overloading concept using C# Language

Jun 30, 2018 overloading, 1119 Views
This Program is used to demonstrate the overloading concept.
using System;

class Box

 {

      private double length;   // Length of a box

      private double breadth;  // Breadth of a box

      private double height;   // Height of a box



      public double getVolume()

        { 

           return length * breadth * height;       

        }

      public void setLength( double len )

       { 

           length = len;     

       }

      public void setBreadth( double bre )

      { 

         breadth = bre;     

       }

      public void setHeight( double hei )

      {  

         height = hei;     

      }

      public static Box operator+ (Box b, Box c)

       {

         Box box = new Box();

         box.length   = b.length + c.length;

         box.breadth = b.breadth + c.breadth;

         box.height   = b.height + c.height;

         return box;

       }

   }

   class Tester

    {

      public static void Main()

       {

         Box Box1 = new Box();

         Box Box2 = new Box();

         Box Box3 = new Box();

         double volume = 0.0;   

         Box1.setLength(6.0);

         Box1.setBreadth(7.0);

         Box1.setHeight(5.0);

         Box2.setLength(12.0);

         Box2.setBreadth(13.0);

         Box2.setHeight(10.0);

         volume = Box1.getVolume();

         Console.WriteLine("\nVolume of Box1 is : {0}", volume);

         volume = Box2.getVolume();

         Console.WriteLine("\nVolume of Box2 is : {0}", volume);

         Box3 = Box1 + Box2;

         volume = Box3.getVolume();

         Console.WriteLine("\nVolume of Box3 is : {0}", volume);

           }

}
A to Z Full Forms and Acronyms

Related Article