In Object Oriented Programming, how would you describe encapsulation?
encapsulation = Binding + Hidding;
In the example given, I would set the age variable to be private. If you don't, there is no need for the Calc_age method to return the value as you cann directly access the age variable.
public class person_details{
private int age; public int Calc_age() { return age; }}
For example in C#, this class could be
public class PersonDetails{ private int age; public PersonDetails() { }
public PersonDetails(int age) { this.age = age; } public int Age { get { return age; } set { age = value; } }}
Then the class could be used as follows:
PersonDetails pd1 = new PersonDetails();pd1.Age = 37;Console.WriteLine("Age is: {0}", pd1.Age);or, setting the age value through the constructorPersonDetails pd2 = new PersonDetails(37);Console.WriteLine("Age is: {0}", pd2.Age);
The point here is, the age variable is not directly accessible, values for it can only be set or obtained using the defines Age property.
encapsulation is process of keeping data inside object( data meas methods and properties ,data member of object)
Example is
public class person_details
{
public int age;
public int Calc_age()
return age;}}
binding th data into single unit
The encapsulation of instance variables is sometimes also called information hiding. Encapsulation is hiding detail which the user donn't want to see.Through this we display those thing which the user wann't to see and hiding background detail.Interface is best example of encapsulation where implementation is depend upon the class which implement it so it hiding the detail or implementation but it describe behaviour of object. Encapsulation protects an implementation from unintended actions and inadvertent access.
The separation of interface and implementation.