Win a copy of Getting started with Java programming language this week in the Beginning Java forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Members of inner classes  RSS feed

 
Marcel Stör
Greenhorn
Posts: 4
Firefox Browser Mac Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On http://faq.javaranch.com/java/ScjpFaq#tripsTraps it says that

No inner class can have a static member.


While I might have misinterpreted the statement, it's certainly true that static inner classes may have static members:
 
Vishwanath Krishnamurthi
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Its a common misconception. A static class that is nested in a class is called as "static nested class" and not as static inner class. That was the confusion I guess?

Terminolgy:
inner class => any non static nested class
Sun tutorial

Regards,
Vishwa
 
Marcel Stör
Greenhorn
Posts: 4
Firefox Browser Mac Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Was I ignorant all those many years that I've been programming Java? I really wasn't aware of the difference in terminology...

Thanks for the link, but IMO in that article even Sun makes a mess out of those terms. At the end they quite correctly admit that
...the taxonomy of the different kinds of classes in the Java programming language (which can be tricky to describe concisely, clearly, and correctly),...


Today is a good day - I learned something

Regards,
Marcel
 
Krishna Srinivasan
Ranch Hand
Posts: 1879
Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes..static inner classes called as the nested classes..the following program will not work. because it declares static field inside a inner class.
 
Robin Paul
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since your confusion is already clear please do remember that the modifier static always means that it belongs to class and is treated as member. That is why static inner class is called a member class and not inner. So if you do hear inner classes it will mostly refer to non static inner class and local inner classes.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!