PostHeaderIcon Java Method Local Inner Class

public class MethodLocalInnerClassOuter
{
private int testVariable1 = 10;
public void outerClassMethod()
{
class MethodLocalInnerClassInner
{
public void getTestVariable1()
{
System.out.println(“Test variable 1 = “+testVariable1);
}
}
MethodLocalInnerClassInner m = new MethodLocalInnerClassInner(); //A method local inner class can only ever be instantiated inside themethod that uses it.
m.getTestVariable1();
}

public static void main (String args[])
{
MethodLocalInnerClassOuter m1 = new MethodLocalInnerClassOuter();
m1.outerClassMethod();
}
}

Leave a Reply

You must be logged in to post a comment.

Adsense