Chapter Six, Sethi

Groupings of Data and Operations

Information Hiding:

" 'We're Watchmen,' said Cuddy. 'Our job is to keep the peace.'

'Good,' said Stronginthearm. 'Go and keep it safe somewhere until we need it.' "

Terry Pratchett "Men At Arms" p.203

Like C++, Java is an object oriented language. It is possible to write code with a high degree of information hiding. Many programming environments (e.g. Visual J++) will create accessor methods for private class variables automatically for the programmer.


Java code is organized in packages, which contain related classes and define namespaces. There are four types of access levels in Java. Java has the same public, private and protected keywords as in C++. In addition the default access is package level. Any file not explicitly included in a package is put in an anonymous package. Note, this anonymous package is NOT unique - all anonymous classes are considered to be in the same package and have free access to each others private variables.

Multiple inheritance is not allowed. A Java class can only extend one class. Instead of multiple inheritance Java introduces interfaces. A Java class can implement any number of interfaces, including marker interfaces.