Inner Classes
Classes, as we have seen so far, cannot be hidden to other parts of the program. In code terms, they cannot be made private. To offer this kind of security mechanism, Java developed so-called inner classes. This type of class is declared nested within other classes. A quick example of this follows:
Example16.java
1Â Â class Container { 2Â Â Â Â Â Â // inner class 3Â Â Â Â Â Â private class Continent { 4Â Â Â Â Â Â public void print() { 5Â Â Â Â Â Â Â Â Â Â Â Â Â Â System.out.println("This is an inner class"); 6Â Â Â Â Â Â Â Â Â Â } 7Â Â Â Â Â Â } 8Â Â 9Â Â Â Â Â Â // method to give access to the private inner class' method 10Â Â Â Â Â void printContinent() { 11Â Â Â Â Â Â &...