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

Is char * a string?

637


What are the basic concepts of OOPS in java?

647


Why is java so important?

736


define the terminology association.

726


What is a lambda expression ? What's its use ?

651






Can we declare an interface as final?

670


What is the difference between the reader/writer class hierarchy and the inputstream/outputstream class hierarchy in java programming?

710


What class of exceptions are generated by the java run-time system?

739


Compare Mutex and Semaphore in java.

637


Explain jdk, jre and jvm?

657


What is difference between char array and string?

629


Write java program to reverse string without using api?

628


What is stringwriter?

630


What is the purpose of a parameter?

628


How do you define a method?

606