Java- Inner Class Example

//Example of inner class(nested class)
//1.static   nested class(if inner class is static it must access the member of its
// it's enclosing class through object.therefor rarely used )

//2.nonstatic   nested class known as inner class( outer class can create and acess property and behaviour on inner class but vice versa is not true)

class A  //outer class of B
{
int a=100;
A()
{
B obj=new B();
obj.display();
}

//inner class B it's members are visible to class A but not to A's child
 class B
  {
   int b=200;
   B()
    {
//A obj=new A();//not possible
 // System.out.println("a="+obj.a);
   

   }
  void display()
{

  System.out.println("a="+a);
}

  }


}






class Test
{
public static void main(String ar[])
{

A obj=new A();
}

}
Reactions: