This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes question about static inner class? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "question about static inner class?" Watch "question about static inner class?" New topic

question about static inner class?

dragon ji
Ranch Hand

Joined: Oct 31, 2002
Posts: 110
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.

scjp 1.4<br />challenge haven't limit!
Dan Chisholm
Ranch Hand

Joined: Jul 02, 2002
Posts: 1865
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.

Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="" target="_blank" rel="nofollow">Try my mock exam.</a>
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
If x is an instance field the compiler will not allow to access it from a static context.

SCJP2. Please Indent your code using UBB Code
dragon ji
Ranch Hand

Joined: Oct 31, 2002
Posts: 110
I agree. Here's the link:
subject: question about static inner class?
It's not a secret anymore!