Exercises: Inner Classes

A

Create a class that contains a public inner class. In main create an instance of the inner class. Look at the .class file names for the compiled code.

B

Create an outer class that has an inner class. In the outer class create a private method and a private variable. In the inner class create a method that calls the private method and accesses the private variable in the outer class. Explain why this is possible. Does it break the encapsulation of the outer class?

C

In Exercise B, it is shown that an inner class has access the private methods and variables of the outer class. Show whether the reverse is also true, i.e., the outer class can access the private methods and variables in an inner class.

D

Run the JavaDoc tool on the classes in Exercise B without having added any JavaDoc comments to the java source code. Look at the output. Now add full JavaDoc comments on all the constructs in the classes. Rerun the JavaDoc tool and look at the output.

Extra Assignments

E1

Discuss the groups source code documentation strategy for your project. Which constructs should be documented to fulfill the project requirements?