Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • 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:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

What's the difference?

 
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....
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • 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.
 
Humans and their filthy friendship brings nothing but trouble. My only solace is this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic