Here is the error message I got when I compile
Outer.java:5: non-static variable this cannot be referenced from a static context
Inner i = new Inner();
^
1 error
in order to make this code work we need to add static in the inner class then only static void main method can access inner class. static only acces static!
here is working code!
public class Outer {
public String name = "Outer";
public static void main(String argv[])
{
Inner i = new Inner();
i.showName();
}//End of main
private static class Inner {
String name =new String("Inner");
void showName()
{
System.out.println(name);
}
}//End of Inner class
}