can we create a instance for intwerface?

Answer Posted / amit kumar gautam

Though it is correct that interfaces are basically used for
obtaining the dynamic resoulution of the Method and they
usually can not be instantiated but it is also possible to
instantiate the same in case of anonymous classes and it
works fine.......


class Amit
{

void addCode()
{
Runnable rr=new Runnable()
{
public void run()
{
System.out.print("This is Amit")
}
};
Thread tt=new Thread(rr);
tt.start();

}
}

class Check
{
static public void main(String[]amit)
{
new Amit().addCode();
}
}

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What happens if an exception is throws from an object's constructor?

917


How are java objects passed to a method and what are native methods?

862


Explain the differences between static and dynamic variables?

894


How do you use parseint in java?

757


Is it possible to define a method in java class but provide it’s implementation in the code of another language like c?

854


Explain notify() method of object class ?

890


Why wait and notify methods are declared in object class?

831


What is array length in java?

764


What is the difference between sop and work instruction?

720


what is meant wrapper classes?

861


Why is java called java?

822


What is parsing a sentence?

793


What is pass by value?

737


Why we used vector class?

863


What is Recursion Function?

916