HTML & JS
// Java program to demonstrate accessing 
// a static nested class

// outer class
class OuterClass
{ 
	// static member
	static int outer_x = 10;
	
	// instance(non-static) member
	int outer_y = 20;
	
	// private member
	private static int outer_private = 30;
	
	// static nested class
	static class StaticNestedClass
	{
		void display()
		{
			// can access static member of outer class
			System.out.println("outer_x = " + outer_x);
			
			// can access display private static member of outer class
			System.out.println("outer_private = " + outer_private);
			
			// The following statement will give compilation error
			// as static nested class cannot directly access non-static membera
			System.out.println("outer_y = " + OuterClass.this.outer_y);
		
		}
	}
}

// Driver class
public class StaticNestedClassDemo
{
	public static void main(String[] args)
	{
		// accessing a static nested class
		OuterClass.StaticNestedClass nestedObject = new OuterClass.StaticNestedClass();
		
		nestedObject.display();
		
	}
}

Generated URL:

Compile Errors :

prog.java:29: error: non-static variable this cannot be referenced from a static context
			System.out.println("outer_y = " + OuterClass.this.outer_y);
			                                            ^
1 error

Output:

No Output
Report Bug