You are on page 1of 2

we can create inner class only with the help of outer class object

Method local inner classes

>>mehthod local inner class is defined within a method of enclosing class

>>only to modifiers are allowed for method local inner classess that are : abstract
and final

ex:

class MyOuterDemo{

private int x = 100;

public Methodout(){
//local variable
final String name = "Charshini"; //without final get erro
}

//Inner class that is declared insed the method


class MyInnerDemo{
public MethodIn(){
sysout("Outer variable value x: "+x);
sysout("Method variable name: "+name);
}
MyInnerDemo m1= new MyInnerDemo ();
m1.MethodIn()
}

ex:

public void myFun(){

int x,y;

Anonimus Inner class


Class without a name. usually declaered with clode block

Class Pizza {
public class eat(){

sysout("I love pizza");


}
}

class Food{

Pizza p = new Pizza(){


public void eat(){
sop("I love to eat burger");
}
};
}
----------------------------------------------------

Static nested class: access only static members, static members of outer class.

Inner class and static nested class

we cannot create object in inner class without outer class object

static nested class without using outer class object we can create inner class
object

You might also like