• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Query from JLS

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
srikrish
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for explaining Sunita. So, is member class just another name for static inner classes or are the two separate but similar entities?
Srikrish
 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sandeep, you seem to have said it all. Unless you want to get into Local Classes and Anonymous Classes :-)
BTW Member Classes are sometimes called Nested...
Regards
Harry
 
srikrish
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Sandeep. That puts things in the right perspective for me.

 
Sunita
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Thanks sandeep for your help .Now I got clear idea about inner classes..
Regards
Sunita
 
Time is the best teacher, but unfortunately, it kills all of its students - Robin Williams. tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic