A regular inner class is a nested class that only exists within an instance of enclosing class. In other words, you cannot instantiate an object of an inner class without first having an object of the outer class. An inner class can use all the methods and fields of the outer class even the private ones directly. The methods and fields of outer class are used as if they were part of the inner class.
The following program demonstrates the concept of inner class
class outer
{
private double i = 11.5 ;
private static String str = "Hi Dinesh";
class inner
{
int j ;
public void display()
{
j = 5;
System.out.println("j = " + j);
System.out.println("j = " + i);
System.out.println("str = " + str);
}
}
}
class InnerClass
{
public static void main(String[] args)
{
outer outobj = new outer(); //create instance of enclsing class
outer.inner innobj = outobj.new inner(); // create intansce of
//regular inner class
innobj.display();
}
}