3

Netbeans prevents me from making a static class. How can I make one?

I made class like: right click on project > new > Java Class. Then I just add a static keyword on the class created.

krato
  • 1,226
  • 4
  • 14
  • 30
  • ..and [Why are you not able to declare a class as static in Java](http://stackoverflow.com/questions/3584113/why-are-you-not-able-to-declare-a-class-as-static-in-java) – mattias Jun 06 '14 at 10:48

3 Answers3

4

You can create a static class as a nested class and not the main class. So, the Netbeans is not allowing you.

class MainClass {
    ...
    static class InnerClass {
        ...   
    }
}
lpratlong
  • 1,421
  • 9
  • 17
Gaurav
  • 531
  • 1
  • 4
  • 15
2

You can not!

Only public, final and abstract modifier are allowed in a Java Class.

However, you can write a static, private nested class. But only in nested class.

lpratlong
  • 1,421
  • 9
  • 17
1

Static class are Nested Classes. You cannot create a new class (a new file .java) marked by static modificator.

Yohji
  • 170
  • 8