What is the Encapsulation

 Posted by Chandra.Shekhar on 4/25/2012 | Category: C# Interview questions | Views: 1802 | Points: 40

Encapsulation is a process of binding the data members and member functions into a single unit.
Example for encapsulation is class. A class can contain data structures and methods.
Consider the following class
public class Aperture
public Aperture ()
protected double height;
protected double width;
protected double thickness;
public double get volume()
Double volume=height * width * thickness;
if (volume<0)
return 0;
return volume;
In this example we encapsulate some data such as height, width, thickness and method Get Volume. Other methods or objects can interact with this object through methods that have public access modifier

Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response

More Interview Questions by Chandra.Shekhar