Given the following question, I am definate about option e as correct, but for non-static inner classes should'nt option c also hold correct considering (new outer.new inner) must be mentioned in the enclosing class. Thanx 5. 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.
I think only E is correct in this case. A)It must implement an interface. - FALSE. There is no such condition. B)It is accessible from any other class. - FALSE.Not always.If we have a private non-static inner class then it is NOT accessible even if we do have an istance of the outer class available with us. C)It can only be instantiated in the enclosing class - FALSE.It can be instantiated in any class if a reference to the enclosing class is available.It is true if we have a private non-static inner class , but that is not mentioned here. D)It must be final if it is declared in a method scope. - FALSE.No such condition. E)It can access private instance variables in the enclosing object. -TRUE.A non-static inner class can access private member variables of outer class.
------------------ Come on in !! Drinks are on the house in the Big Moose Saloon !!
Udayan Naik<BR>Sun Certified Programmer for the Java 2 Platform