Sunday, 3 May 2015

Private static class in java with example

Private static class in java with example

Below i have written a code which is explaining the concept that how we can create private class in java.


public class HelloWorld{

     public static void main(String []args){
        System.out.println("Hello World");
        B b=new B();
        b.a.Adisp();
     }
}

Example of final class

final class B {

    public static final A a=new A();
 
}

Here class A is having class AA which is private static class. Which can be accesed
from parent class directly using Class name as we are accessing all the static resources of any Class. We can also create a public inner class. We cover it in upcomming articles.

class A {
     private int a=4;
 
     public void  Adisp(){
     
         System.out.println("Hello World" + a);
         AA.AAdisp();
    }
 
    private static class AA{
     
    public static void  AAdisp(){
     
         System.out.println("Hello World 40");
   
    }
 
    }

}