I created a non-static inner class like this:
class Sample { public void sam() { System.out.println("hi"); } } I called it in main method like this:
Sample obj = new Sample(); obj.sam(); It gave a compilation error: non-static cannot be referenced from a static context When I declared the non-static inner class as static, it works. Why is that so?