/**
 * Anonymous Inner Classes
 */
public class Outer7 
{	
	public static void main(String[] args) 
	{
		Outer8 objOuter8 = new Outer8();
		objOuter8.act();
	}
	
	public void eat()
	{
		System.out.println("I am Eat Method");
	}
}

class Outer8 extends Outer7
{
	Outer7 objOuter7 = new Outer7(){
		public void eat()
		{
			System.out.println("I am Overridden Eat Method");
		}	
	};
	
	public void act()
	{
		objOuter7.eat();
	}
}

Output

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

Output

25
I am a Inner Class

The Inner Class Defined with in static method has access to only static variables defined in the outer class

 /**
 * 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

/**
 * Referencing Outer Class Object and Its Value
 */
public class Outer5 
{	
	private int x = 7;
	
	public static void main(String[] args) 
	{
		Outer5 objOuter5 = new Outer5();
		objOuter5.callInnerClassMethod();
	}
	
	public void callInnerClassMethod()
	{
		Inner5 objInner5 = new Inner5();
		objInner5.InnerClassMethod();
	}
	
	public class Inner5
	{
		private int x = 5;
	
		public void InnerClassMethod()
		{
		 System.out.println(x);
		 System.out.println(Outer5.this.x);
		}
	}
}

Output

5
7
public class Outer1
{
	public static void main(String[] args) 
	{
		Outer2 objOuter1 = new Outer2();
		Outer2.Inner1 objInner1 = objOuter1.new Inner1();  
		objInner1.innerMethod1();
	}
}

class Outer2 
{	
	public void makeInner()
	{
		Inner1 objInner1 = new Inner1();
		objInner1.innerMethod1();
	}
	
	class Inner1
	{
		public void innerMethod1()
		{
			System.out.println("This is Inner Method1");
		}
	}
}

Output

This is Inner Method1
public class Outer1
{
	public static void main(String[] args) 
	{
		Outer2 objOuter1 = new Outer2();
		Outer2.Inner1 objInner1 = objOuter1.new Inner1();  
		objInner1.innerMethod1();
	}
}

class Outer2 
{	
	public void makeInner()
	{
		Inner1 objInner1 = new Inner1();
		objInner1.innerMethod1();
	}
	
	class Inner1
	{
		public void innerMethod1()
		{
			System.out.println("This is Inner Method1");
		}
	}
}