What is Encapsulation....
If you will Search it you find a simple definition: Data hiding....

Now,

1) First Example: -
============

    Class Employee
    {
        public int age;
    }



2) Second Example: -
===============

    Class Employee
    {
        private int age;
    
        public int getAge(){return age;}
    }

Question: -
===========
In both the above specified examples, There is no data hiding. As age is either being modified by others or being viewed by others. Where is Data Hiding? How encapsulation help in these examples(specified above).

Can anyone tell me?


-Anil


What is Encapsulation....
===

If you will Search it you find a simple definition: Data hiding....

Now,

1) First Example: -
============

    Class Employee
    {
        public int age;
    }



2) Second Example: -
===============

    Class Employee
    {
        private int age;
    
        public int getAge(){return age;}
    }

Question: -
===========
In both the above specified examples, There is no data hiding. As age is either being modified by others or being viewed by others. Where is Data Hiding? How encapsulation help in these examples(specified above).

Can anyone tell me?


-Anil

