Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors

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();
    }      
  }
}

2 thoughts on “Implement Encapsulation in C#”

  1. After reading your article, I learned many new things about planning adventures abroad. I want to express my gratitude for sharing your travel knowledge and experience with us. We discussed a similar topic on TravelForums. Keep up the amazing work!

  2. Howdy, i read your blog occasionally and
    i own a similar one and i was just curious if you get a lot of spam
    feedback? If so how do you reduce it, any plugin or anything you can advise?
    I get so much lately it’s driving me crazy so any assistance is very much appreciated.!

Leave a Comment