First you have to understand what encapsulation means...in a nutshell it means, the user of a component is provided with the functionality but the user is not told how that functionality is actualy provided/implemented internally by that component. If we go deep, this essentially means the fields of a class (which probably may hold some data, some state information or whatever) are not exposed to the user. But public methods are provided which let the user access those fields.
Let's take an example, you may write a class that represents an Employee. Now, there can be a lot of fields in the class like name, age, experience, etc. There may be a method 'getRating()' which rates an employee for appraisal purposes. Let's say this method is implemented such a way that it returns rating based on just experience.
Now, there are two options
1. just provide getRating() method and do not expose the experience field.
2. expose the experience field, and then there is no need to write getRating() method as the user of this class can calculate the rating himself!
Suppose we choose option 2 and other classes start using the experience field as they please....an year down the line, manangement says that rating should not just be based on experience but also on last year's performance!
What happen's to all that code that made use of just the experience field to calculate the rating? You have to change all that code.
Had we chose option 1, we would only have to change the method getRating() and that's it, we are done. This is what is meant by encapsulation. We encapsulated ( hid it from the user) the internal details ( ie. the field experience) and exposed just the functionality (ie. the method getRating() )
Now it's easy to analyse the given choices....
4)It changes the implementation without changing the interface and causes no consequential changes to other code.
We saw that we changed the implementation of getRating() method and nothing else broke!
5)It changes the interface without changing the implementation and causes no consequential changes to other code.
No, it did not change the interface, other classes will still use the same method getRating().
HTH,
Paul.
------------------
Get Certified, Guaranteed!
http://www.enthuware.com/jqplus