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

Can I declare class as static or private?

541


Can you sort a string in java?

489


Why java uses the concept of the string literal?

543


What does || || mean in math?

513


Can an interface have a class?

563






what is singleton in java?

598


What is function overriding and overloading in java?

581


What is the disadvantage of synchronization?

557


What are peerless components?

618


Can we override static methods in java?

585


Is null an object in java?

563


If we don’t want some of the fields not to serialize how to do that?

565


What are default methods ?

579


What is a method type?

532


What is the concatenation operator in java?

578