Monday, November 17, 2014

Java: Information hiding using interfaces

Typically, the "private" key word is used to hide any methods/attributes from other classes. However, there are cases where a class has one set of methods that is used by class A and another set of methods that are used by class B which means that all these methods have to be public. To prevent class A from accessing methods meant for class B, we can use interfaces as depicted in the following example:


No comments: