*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes class inside top-level nested class. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "class inside top-level nested class." Watch "class inside top-level nested class." New topic
Author

class inside top-level nested class.

G Nadeem
Ranch Hand

Joined: Apr 25, 2003
Posts: 48
hi,
i wonder where i am making a mistake here.

is the class InsideStatic is static. if no why i cant leave name variable non-final. if yes why an instance of InnerInsideStatic is not required inside main method, to access variable 'name'.
plz correct where i am wrong. :roll:
Lawrence Chettiar
Ranch Hand

Joined: Apr 10, 2003
Posts: 62
Nadeem
Nice question,
well to answer your questions
"is the class InsideStatic is static"
Nope it is not.
if no why i cant leave name variable non-final
Becoz a inner class which is not static cannot have a static variable which is not final.
Now to answer second part of question
"if yes why an instance of InnerInsideStatic is not required inside main method, to access variable 'name'."
You don't need a class to be static to access its static members. Hence even though the InsideStatic is not static u can acces its variable 'name'.


SCJP 1.4 (86%)<br />SCMAD Beta (77%)<br />SCEA (part I:89%,partII:93%)<br />MCAD (cleared 70-315 & 70-320 [Score 980])
G Nadeem
Ranch Hand

Joined: Apr 25, 2003
Posts: 48
thanks Lawrence..
You don't need a class to be static to
access its static members.

got to keep ALL things on top of head. isn't it.
Yi Meng
Ranch Hand

Joined: May 07, 2003
Posts: 270

Becoz a inner class which is not static cannot have a static variable which is not final.

Just realize this point, thanks a lot.
previously i was thinking non-static inner class cannot have static members, by all means........


Meng Yi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: class inside top-level nested class.
 
Similar Threads
Why local inner classes CAN "see" final variables?
Confused with inner and nested classes
Inner Class Final vaiable reference
Core Java Basic
what should be the output???