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 are some characteristics of interference class?

529


Can an interface have a constructor?

526


What are three types of loops in java?

600


What is the basic concept of java?

547


Write a regular expression to validate a password. A password must start with an alphabet and followed by alphanumeric characters; its length must be in between 8 to 20.

604






What are the advantages of assembly language?

509


Can inner class final?

647


Do we need to manually write Copy Constructor?

614


What are the main differences between notify and notifyAll in Java?

595


What will be the initial value of an object reference which is defined as an instance variable?

653


What is the difference between stream and buffer?

521


How many types of flags are there?

530


What is boolean query?

538


What is parsing in java?

540


How to instantiate static nested classes in java?

570