Use of inner class

public  class  UseOfInnerClass {
static int d=5;
  static  class  inner {
        void msg(){
            System.out.println("i am in inner class " +d); // for accessing d the classs is made static        //because static variable can be acessed by static class only
        }
    }
   
   
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
       
     
     UseOfInnerClass.inner ob =new UseOfInnerClass.inner(); // calling method of inner class
        ob.msg();
}
}


output

i am in inner class 5

No comments:

Post a Comment