I was going through an earlier discussion about �Extending Inner Classes�.
The conclusion drawn was �Inner classes cannot be extended outside their outer scope�
http://www.javaranch.com/ubb/Forum24/HTML/001456.html However, an outer class can extend non-local inner classes though it is not very straightforward.
To extend inner classes, the inner class should have a special constructor that takes a reference to an object of the outer class as an argument. Inside this constructor, a call like �outerclass.super()� should be made to associate the outerclass object to the innerclass object being created. Note that the extended class cannot define a default constructor.
If you know, please share whether this is a specified behaviour or is a hack - fooling the compiler - that may no longer work in future. I think, JLS doesn�t mention about extending inner classes in this way. Is it relevant to
SCJP exam? What would be the answer to the SCJP question: A non-static inner class can be extended by code outside the enclosing class (True/False)?
An example of extending an inner class outside its enclosing class follows.
Please correct me if I am wrong.
Thanx,
RajSim
Output:
O + E
O.display
O.I.display
E.display