Originally posted by Anupam Sinha:
With my limited brain the only answer that comes to my mind is Inner classes. Is that the answer? That is, indeed, the answer. The following code fails:
This code fails because, when a class in initialized, the constructor of that object invokes the constructor of the parent class. In this case, the constructor of the parent class is private so we end up with a compiler error. There is no way to instantiate the class Super
outside of the class definition, itself.
However, the following code works just fine.
This works because an inner class is allowed to access private members of its enclosing instance, including the private constructor. Of course, if you were to take that second example and mark Super as final...
As Kathy mentioned, I don't know that I can think of a good reason to ever do this in a real application. However, when it comes to the
SCJP exam, you're required to know a lot of things that might never come up in a real application. :roll:
I hope that helps,
Corey
[ March 30, 2004: Message edited by: Corey McGlone ]