What is a "static class" in Java? Explain with examples
Hello, colleagues! I recently started learning Java and came across the term "static class". I think I understand the concept of "static" for fields and methods — it means they belong to the class, not to an instance. But when it comes to an entire class, I get confused.
I tried writing this code:
```java
public class Main {
public static class Helper {
public void printMessage() {
System.out.println("Hello from static class!");
}
}
public static void main(String[] args) {
Helper h = new Helper();
h.printMessage();
}
}
```
This works. But if I remove the word `static` before `class Helper`, it also works. So what's the difference? And in what situations should I use `static` for a class?