NON STATIC INNER CLASS
       whenever class is  define without static keyword  that is 
       class non  static inner class.
 following characteristics


1)It's object cannot created independently thats means object of outer class is require for  instantiate inner class Object
 OuterClass ref = new OuterClass();
 OuterClass.InnerClass ref2 =  ref.new InnerClass();



2) It can access  private static  and non static datamember  of its Outerclass inside the inner class.
 ex
  class Outer
{
  private int x; \\ non static datamember
 private  static y;\\ static datamember
 Outer(int a) \\ constructor
{
  x=a;   
}
 static\\ static block for instantiate
{

}
 class Inner 
{
   int z;
  Inner(int z)
 {
     this.z=z;
 }
 public void display()
{
  System.out.println(" value of  non static data member  of  outer class"+x) ;
 
  System.out.println(" value of   static data member  of outer class"+y) ;
  System.out.println(" value of  non static data member of innerc class "+z) ;
}
 }  
}
===============================================
 JRE MAKE FOLLOWING CHANGES
 1)jre create  reference of class type in inner class like
     clasa Outer$Inner
{ 
  int z;
  final Outer this$0;
  // method if any
}
 2) jre modified inner class constructor for initialize outer class reference variable
 public Outer $Inner(Outer r,int z)
{
  this$0=r;
 this.z=z;
}

Comments

Popular posts from this blog