This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
This one is from JTest Which statement is true about a non-static inner class? A. It must implement an interface. B. It is accessible from any other class. C. It can only be instantiated in the enclosing class. D. It must be final if it is declared in a method scope. E. It can access private instance variables in the enclosing object. Ans given is E. My ans B,D,E I think B is partially true. inner class can be accessed from outer class if it is not declared private.(and ofcourse we have to create the instance of enclosing class). c)inner class inside method scope is implicitly final We cannot subclass an inner class declared inside a method scope. Please correct me if I am wrong.
Mani,I Innerclasses declard with in the method scope can be declared abstract or final. When I heard this, even I got . I really don't know how this feature can be used, but it helps to remember this for the exam Hope this helps.
Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
Mani, B is obviously wrong. You should pay attention the phrase "any class". Surely an inner class is not accessed from any class, its accessibility outside the class in which it is defined will depend upon the its access modifiers and those of its encompassing class. And for a local inner class (one declared inside a method), you should know that it can never be declared as private,static,public or protected.And being local, you know that it exists only for as long as the method that contains exists. So it can only be accessed in the class that it is contained. D is also wrong. You are right to say that local inner classes are implicitly final. Again pay attention to the phrase "must ". It is not a must that they be declared final, but they may be declared final, redundant though. I think such phrases are what we ought to watch out for when deciding which answer is correct.
What do you think?
Joined: Apr 20, 2000
I think I have to study little bit of English Grammer also for the Sun Certification Exam.