aspose file tools
The moose likes Beginning Java and the fly likes can a class be static? 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
Reply Bookmark "can a class be static?" Watch "can a class be static?" New topic
Author

can a class be static?

santhoshkumar samala
Ranch Hand

Joined: Nov 12, 2003
Posts: 156

hello I am new to java can any body please tell me the answer for this Qn
can a class be static? if not then why?


santhosh<br />SCJP,SCWCD
Landon Blake
Ranch Hand

Joined: Dec 04, 2003
Posts: 121
Yes, a class can be static. This is done by creating the class with the
"static" keyword in the class statement.
Example:
public static class MyClass{
Here is an article that explains which types of classes can and can't be declared as static:
http://www.javaworld.com/javaworld/javaqa/1999-08/01-qa-static2.html
I hope that helps.
Landon
[ May 06, 2004: Message edited by: Landon Blake ]
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
A top-level, outer class cannot be static.
Only a class declared inside another class can be declared static. These are sometimes called nested top-level classes.
[ May 06, 2004: Message edited by: Dirk Schreckmann ]

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: can a class be static?
 
Similar Threads
doubt on Inner class
static and serialization
Inner Classes Q
Static class??
Static Class