Thursday, August 17, 2017

Encapsulation

Encapsulation can define the program to hide unwanted code within the capsule and shows essential features. Encapsulation is implemented by access modifiers.These five modifiers allow using in encapsulation.Public, Private, Protected, Internal, Protected internal.

Why  Encapsulation for? 

Encapsulation means protecting important data inside the class that we don’t want to be exposed outside the class using the system.

namespace RApplication
{
   class R
   {

      private int length;
      private int width;
     
      public void Details()
      {
         Console.WriteLine("Enter Length: ");
         length = Convert.ToDouble(Console.ReadLine());
         Console.WriteLine("Enter Width: ");
         width = Convert.ToDouble(Console.ReadLine());
      }
      public double GetArea()
      {
         return length * width;
      }
      public void Display()
      {
         Console.WriteLine("Length: {0}", length);
         Console.WriteLine("Width: {0}", width);
         Console.WriteLine("Area: {0}", GetArea());
      }
   }
  
   class ExecuteR
   {
      static void Main(string[] args)
      {
         Rectangle r = new Rectangle();
         r.Acceptdetails();
         r.Display();
         Console.ReadLine();
      }
   }
}

No comments:

Post a Comment