Java Concepts | Techbirds

TYPES OF INNER CLASS IN JAVA

1. Non static Inner class 2. Static Inner class 3. Method Local Inner class

4. Anonymous Inner class


// 1. ..................................Non static inner Class...............................

class Outer { void outer() { System.out.println(“outer”);

}

class Inner { void inner() { System.out.println(“inner”); } } } class Manager { public static void main(String …arg) { Outer.Inner ob=new Outer().new Inner();

ob.inner();

Outer o1=new Outer();
o1.new Inner().inner();

new Outer().new Inner().inner();

}
}

// 2. ……………………………..static inner class………………………….

class Outer { static void outer() { System.out.println(“outer”);

}

static class Inner
{

void inner() { System.out.println(“inner”); outer(); } } } class Manager { public static void main(String …arg)

{

Outer.Inner ob=new Outer.Inner(); ob.inner(); }

}

// 3. …………………………Method local inner class……………………….. class Outer { void show() {

int a;

class Inner { void disp()

{

System.out.println(“disp()”); } } new Inner().disp(); } } class Manager { public static void main(String …arg) { new Outer().show(); }

}

//………………………….. 4. Anonymous inner class………………………….

interface I { public abstract void show(); } class Manager implements I

{

public void show()
{

System.out.println(“show() of Manager class”);
}

public static void main(String …arg)
{

I ob=new I(){

public void show()
{

System.out.println(“show() of Anonymous inner class”);
}

}; ob.show(); }

}

369 total views, 2 views today

Share this Onfacebook-3910631twitter-9792334linkedin-4710756google-3040040