Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

question about static inner class?

 
dragon ji
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is this statement right?
Instance members of a static inner class can be
referenced using the class name of the static inner class.
help me ,please.
 
Dan Chisholm
Ranch Hand
Posts: 1865
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By definition the term "static inner class" is contradictory. An "inner class" is a nested class that is not static.
A static nested class behaves like a top-level class. An instance of a static nested class can be created without first creating an instance of the enclosing class.
Yes, it is possible to access a field, x, of a static nested class using an expression such as OuterClassName.StaticNestedClassName.x.
 
Jose Botella
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If x is an instance field the compiler will not allow to access it from a static context.
 
dragon ji
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanx!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic