1

I am trying to create static class in Java Web Application using eclipse. but it says

Illegal modifier for the class ClassName; only public, abstract & final are permitted

can we create static class in web application ? if no why ?

1
  • What do you expect to achieve with this "static class"? That all methods in the class are static? Because then you should declare all methods to be static, not the class. Commented Sep 6, 2013 at 12:10

5 Answers 5

5

No, because there are no static top-level classes in Java.

Sign up to request clarification or add additional context in comments.

Comments

3

Static class you can create in general only as nested class in another class. This has nothing to do with Web-Application. It has a general validity in Java.

Each compilation unit should contain a public or default (non-static) class. Then within it you can declare static nested classes.

2 Comments

inner and static are mutually exclusive. See JLS #8.1.3.
@EJP: Ok, I wrote the word with its general meaning, irresprective of how one calls it in Java. I have corrected it.
3

Only inner classes can be made as static. That means except inner class you can not create static class

3 Comments

Only nested classes can be made static. If you make an inner class static it ceases to be inner. See JLS #8.1.3.
@EJP I got total 5 upvotes for this answer then this means that those users who gave upvotes accepts that my answer is right.So you should read answer thoroughly once again
You should read the part of the Java Language Specification I cited, thoroughly, before commenting again. It doesn't agree with you.
2

A static class is, in practice, nothing else than a standard non-inner class declared in another class.

In other words, your app web application has nothing to do with classes being declared as static or not.

Comments

1

Outer class cannot be static. Only nested class can be static. For example below is possible

class OuterClass {      
    static class StaticNestedClass {
       ...
    }    
}

But not

static class OuterClass {      
 ...
}

2 Comments

Only nested classes can be made static. If you make an inner class static it ceases to be inner. See JLS #8.1.3.
@EJP Thanks for your comments and the JLS reference. I had checked here too. Updated by reply.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.