Search your topic here

Implement Encapsulation in C#

PRINCIPLES OF PROGRAMMING LANGUAGES
PRACT. Implement Encapsulation in C#.

using System;

namespace ATC
{
    class AreaDimension
    {
      public double length;
      private double width;
      
      public double GetWidth() {
         Console.WriteLine("Enter Width here becuase its private: ");
         width = Convert.ToDouble(Console.ReadLine());
         return width;
      }   
   }
   
   class FindArea {
      static void Main(string[] args) {
         AreaDimension obj = new AreaDimension();
         obj.length = 4.5;
         Console.WriteLine("Area = {0}", (obj.length)*(obj.GetWidth()));
         Console.ReadLine();
    }      
  }
}

LEAVE A REPLY