In Object Oriented Programming, how would you describe encapsulation?
By in OOP/OOD on Nov 28 2006
  • Pramod Lawate
    Aug, 2016 26

    encapsulation = Binding + Hidding;

    • 0
  • Phil Curnow
    Jun, 2009 14

    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 constructor

    PersonDetails 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.

    • 0
  • Shaik Hanumantha Rao
    Jun, 2007 4

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

    • 0
  • Apr, 2007 9

    binding th data into single unit

    • 0
  • amit singh
    Feb, 2007 15

    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. 

    • 0
  • sai
    Nov, 2006 28

    The separation of interface and implementation.

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS