Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

why a class can't declare it as static ?  RSS feed

 
Edward Chen
Ranch Hand
Posts: 798
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why a class can't be declared as static , like "public static class Test" ?

Thanks.
 
John de Michele
Rancher
Posts: 600
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 237
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!