Static Inner Class in Java
The static keyword is used on a class, method, or field to make them work independently of any instance of the class.Static fields are common to all instances of a class. They do not need an instance to access them.
Code Snippet
// Static Inner Class in Java
class OuterClass {
static int x = 10;
int y = 20;
static class InnerClass {
void display() {
System.out.println("X : " + x);
}
}
}
public class App {
public static void main(String[] args) {
OuterClass.InnerClass i = new OuterClass.InnerClass();
i.display();
}
}