Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Top level class

 
Rani Vish
Greenhorn
Posts: 22
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

why we can not make top level class static

Thanks
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ask yourself: What would it mean for a top-level (non-nested) class to be static?
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by marc weber:
Ask yourself: What would it mean for a top-level (non-nested) class to be static?


Perhaps it could mean that all its fields would be implicitly static. So

Isn't there something like that in VB?
 
Peter Chase
Ranch Hand
Posts: 1970
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jeff Albertson:
Isn't there something like that in VB?


That's the best argument I've heard for not including a language feature.
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Peter Chase:

That's the best argument I've heard for not including a language feature.


*Meow* Very catty!
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jeff Albertson:
... Perhaps it could mean that all its fields would be implicitly static...

Okay, that would be a reasonable interpretation (and it did cross my mind when I phrased the question that way), but in this forum, we should be clear...

Java does not allow static as a modifier for top-level (non-nested) class definitions.

In Java, static essentially means "associated with the class." For fields, this means there is only one location in memory, allocated when the class is loaded. The single field stays with the class, regardless of how many instances might be created. For methods and nested class definitions, this means that there is no implicit "this" reference to the enclosing instance. For initializers, this means the code is executed when the class is loaded.

So for a top-level (non-nested) class, there is no enclosing class to associate with, and static has no meaning.
[ March 29, 2006: Message edited by: marc weber ]
 
Rani Vish
Greenhorn
Posts: 22
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a Lot !!

For the Response

"associated with the class." For fields, this means there is only one location in memory,


i think this is the most suitable answer for my question
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic