Wednesday, 8 June 2016

Playing with Annonymous inner class


Annonymous inner class

Thread T= new Thread()
{};
//annonumous inner class extends Thread class, in short it's  extedns parent Thread

Runnable R= new Runnable()
{
};
is it possible , yes
it's not runnable object it's an object of annonumous class which implement Runnable
else you can't crate an object of Interface

Example

public class AnnnerClass {

public static void main(String[] args) {

A a=new A()
{

public void m1()
{

System.out.println("spicy");
}
};

a.m1();

}
}


public class A {

public void m1()
{
System.out.println("swetty");
}
}
here annonymous A extends A,  and call child class object.