aspose file tools*
The moose likes Beginning Java and the fly likes why a class can't declare it as static ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "why a class can Watch "why a class can New topic
Author

why a class can't declare it as static ?

Edward Chen
Ranch Hand

Joined: Dec 23, 2003
Posts: 798
why a class can't be declared as static , like "public static class Test" ?

Thanks.
John de Michele
Rancher

Joined: Mar 09, 2009
Posts: 600
Edward:

External (main file) classes cannot be declared static. Internal classes can. What would it mean for an external class to be static?

John.
Embla Tingeling
Ranch Hand

Joined: Oct 22, 2009
Posts: 237
Edward Chen wrote:why a class can't be declared as static , like "public static class Test" ?


An enum with one member has all the properties you would expect from a static class, like



In fact this is by many considered the preferred implementation of a so called Singleton.

 
It is sorta covered in the JavaRanch Style Guide.
 
subject: why a class can't declare it as static ?