aspose file tools*
The moose likes Beginning Java and the fly likes Top level class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Top level class" Watch "Top level class" New topic
Author

Top level class

Rani Vish
Greenhorn

Joined: Feb 03, 2006
Posts: 22
Hi All,

why we can not make top level class static

Thanks
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Ask yourself: What would it mean for a top-level (non-nested) class to be static?


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
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?


There is no emoticon for what I am feeling!
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
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.


Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
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

Joined: Aug 31, 2004
Posts: 11343

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

Joined: Feb 03, 2006
Posts: 22
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
 
subject: Top level class