Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

class inside top-level nested class.

 
G Nadeem
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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'.
 
G Nadeem
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 270
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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........
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic