Register Now

Login

Lost Password

Enter your email to reset your password.

BY Author

Java – Static nested classes

The nested class with static access modifier is called static nested class.

Example

class OuterClass 
{
    static int var1 = 10;
    public static int var2 = 20;
    protected static int var3 = 30;
    private static int var4 = 40;
	
    static class InnerClass
    {
        public void innerClassMethod()
        {
            System.out.println("var1 :: "+var1);
            System.out.println("var2 :: "+var2);
            System.out.println("var3 :: "+var3);
            System.out.println("var4 :: "+var4);
        }
    }
}

class StaticNestedClassDemo 
{
    public static void main(String args[])
    {
        OuterClass.InnerClass iObj = new OuterClass.InnerClass();
        iObj.innerClassMethod();
    }
}

Output

var1 :: 10
var2 :: 20
var3 :: 30
var4 :: 40

 

Leave a reply