Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

why a class can't declare it as static ?

 
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.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic