Hi Everyone, Anyone of u,could u please explain what is the exact mean of the following statement(if possible with eg) "Member classes may be static, in which case they have no access to the instance variables of the surrounding class; or they may be inner classes". Thanks and Regards SUnita
I'm not clear about the term Member classes. Are they the same as inner classes? I know static inner classes cannot access any of the non-static members of the outer class. Could someone explain a little bit about member classes please? Thanks, Srikrish
Member classes are independent classes which exist in a program and they are not associated with the instance of outer class. If an Inner class is static then it is as good as a member class.It is not assiciated with an instance of the outer class. i.e a static inner class == member class. inner classes can access all the variables of outer class.whereas member classes can access only static variables. Hope this helps
Member classes may be static, in which case they have no access to the instance variables of the surrounding class; or they may be inner classes
. I'm confused about this and am going to break this sentence down to map it to my understanding about member classes. 1. Member classes may be static or they may be inner classes 2. In case they are static, they do not have access to the instance variables of the surrounding class. 3. In case they are inner class, they have access to the instance variables of the surrounding class. ( Inner classes need an object of the surrounding class to exist) JLS2 section 8.5 says
A member class is a class whose declaration is directly enclosed in another class.
Conclusion: Unless convinced otherwise, I'm to going believe that a class has types of members: -variables -methods -classes There are 2 types of member classes : -Static member class -Non-static member class(Inner class) Static member classes like static methods do not have the this pointer and cannot access instance data. Inner classes like non-static methods have the this pointer and can access instance data. Please correct me if I'm wrong rgds Sandeep