Searching turns up a simple definition: data hiding.
But, consider the following two examples:
1) First Example:
Class Emp
Say I use your code like this:
Employee employee = new Employee();
int age = employee.getAge();
// Do something with age
Here, unless I look at your source code, I have absolutely no idea how Employee
has calculated its age. For all I know, getAge()
could look like this:
public int getAge() {
return new java.util.Random().nextInt( 100 );
}
or perhaps something even more complicated. I just don't know.
So in your second example, the fact that getAge()
just returns a private member variable is completely hidden from me.