This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design 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