1class JavaExample{
2 private static String str = "BeginnersBook";
3
4 //Static class
5 static class MyNestedClass{
6 //non-static method
7 public void disp() {
8
9 /* If you make the str variable of outer class
10 * non-static then you will get compilation error
11 * because: a nested static class cannot access non-
12 * static members of the outer class.
13 */
14 System.out.println(str);
15 }
16
17 }
18 public static void main(String args[])
19 {
20 /* To create instance of nested class we didn't need the outer
21 * class instance but for a regular nested class you would need
22 * to create an instance of outer class first
23 */
24 JavaExample.MyNestedClass obj = new JavaExample.MyNestedClass();
25 obj.disp();
26 }
27}