• 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
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • 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.
 
I promise I will be the best, most loyal friend ever! All for this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!