Is there anything like static class
in java?
What is the meaning of such a class. Do all the methods of the static class need to be static
too?
Is it required the other way round, that if a class contains all the static methods, shall the class be static too?
What are static classes good for?
Can a class be static in Java ?
The answer is YES, we can have static class in java. In java, we have static instance variables as well as static methods and also static block. Classes can also be made static in Java.
In java, we can’t make Top level (outer) class static. Only nested classes can be static.
static nested class vs non-static nested class
1) Nested static class doesn’t need reference of Outer class, but Non-static nested class or Inner class requires Outer class reference.
2) Inner class(or non-static nested class) can access both static and non-static members of Outer class. A static class cannot access non-static members of the Outer class. It can access only static members of Outer class.
https://docs.oracle.com/javase/tutorial/java/javaOO/nested.html
Well, Java has "static nested classes", but they're not at all the same as C#'s static classes, if that's where you were coming from. A static nested class is just one which doesn't implicitly have a reference to an instance of the outer class.
Static nested classes can have instance methods and static methods.
There's no such thing as a top-level static class in Java.
There is a static nested class, this [static nested] class does not need an instance of the enclosing class in order to be instantiated itself.
These classes [static nested ones] can access only the static members of the enclosing class [since it does not have any reference to instances of the enclosing class...]
code sample: