/**
 * Referencing Method-Local Inner Class
 */
public class Outer6 
{	
	public static void main(String[] args) 
	{
		Outer6 objOuter6 = new Outer6();
		objOuter6.invokeInnerClass();
	}
	
	public void invokeInnerClass()
	{
		class Inner6
		{
			public void displayInnerMsg()
			{
				System.out.println("I am a Inner Class");
			}
		}
		
		Inner6 objInner6 = new Inner6();
		objInner6.displayInnerMsg(); 
	}
}

Output

 I am a Inner Class

You cannot Access local variable of the Method since variables are stored in Stack and object exists in Heap memory.The Stack memory will be blown away once the Method exits.

You can access a variable marked as Private in Outer Class.

You can access local variable marked as Final.

The class inside Method-Local Inner class can be either abstract or final.Other private, public and protected are not allowed

Leave a reply