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
Since you're following up directly on an old post, it might make more sense next time to post your question as a followup to the old post, rather than starting a new thread. The whole thread will then show up as "new" for people logging in, and this way the discussion is easier for everyone to follow. Anyway though... This behavior is indeed specified in the JLS 2nd edition draft, section 126.96.36.199 - Explicit Constructor Invocations. (I don't recall seeing it in the original inner classes specification, but that's too poorly written for me to want to look for it.) I'm pretty sure it's outside the scope of the exam - it's a rather subtle detail. As for the statement: "A non-static inner class can be extended by code outside the enclosing class (True/False)?" - this is true, as you've shown. You appear to have caught the mighty Ajith in an error, congratulations!