Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

What's the difference?  RSS feed

 
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im studying for the SCJP exam, im having difficulty grasping this concept...whats the difference between an inner member class and inner member static class? in layman's term....
 
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Inner member classes are those classes declared within the body of another class without the static modifier. Inner member classes need an instance of their enclosing class in order to be instantiated.
For instance,


"Inner member static class" are called top-level nested class and are also declared within the body of another class but with the static modifier. Top-level nested class do not need an instance of their enclosing class to be instantiated.
For instance,

I suggest you read the following chapter (if not already done): http://developer.java.sun.com/developer/Books/certification/certbook.pdf
Then, you should write some code by yourself trying every little manipulation on inner classes and see what results... This is the best way to get acquainted with inner classes.
 
Ranch Hand
Posts: 1055
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Paolo. An inner member class, that is, a non-static inner class "belongs" to an instance of the enclosing class and only has scope as long as that instance exists. This inner class has access to all members (non-static and static) of the enclosing class, even if its declared private. However, it can only declare non-static members for itself.
On the other hand, a static member class, that is, a top level nested class, doesn't need an instance of the enclosing class, can only access static members of the enclosing class, but can declare both static and non-static members for itself.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!