• Post Reply Bookmark Topic Watch Topic
  • New Topic

can a class be static?  RSS feed

 
santhoshkumar samala
Ranch Hand
Posts: 156
Eclipse IDE Hibernate Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Landon Blake
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!