A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
Win a copy of
The Mikado Method
this week in the
Agile and other Processes
forum!
JavaRanch
»
Java Forums
»
Java
»
Beginning Java
Author
why a class can't declare it as static ?
Edward Chen
Ranch Hand
Joined: Dec 23, 2003
Posts: 758
posted
Oct 28, 2009 15:02:34
0
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
posted
Oct 28, 2009 15:07:00
0
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
posted
Oct 29, 2009 00:21:26
0
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
public enum MyClass { STATIC; public void method() { // ... } // more methods } // MyClass.STATIC.method(); // usage
In fact this is by many considered the preferred implementation of a so called Singleton.
I agree. Here's the link:
http://ej-technologies/jprofiler
- if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
subject: why a class can't declare it as static ?
Similar Threads
can't run
why can't abstract class have abstract static method?
Why inner class can't have static variable
Overriding static methods
Why Class cannot be declared as static ?
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter