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

How many bits is a float?

760


what is the role of xml in core java?? and how we can use it?? can somebody give a sample program with explanation and from where i can read more about xml?????

2025


How do you break a loop?

771


What is exception propagation?

840


Why are generics used?

739


how a programmer confirms that the data submitted has been succesfully inserted into the database(either oracle or my sql).. How a programmer confirm if there is any problem with the program he wrote for insertion... ANS:--- >executeupdate method is having boolean return type, if anything goes wrong in data insertion or data updation, it would return false. otherwise, if it successfully inserts data into the database, it would return true NOW HOW TO I CHECK IN MY DURING EXECUTION WHETHER IT RETURNS TRUE OR FALSE... WELL IT WILL DISPLAY ANY MESSAGE OR NOT

2121


What is the purpose of the wait(), notify(), and notifyall() methods in java programming?

780


Which is better stringbuffer or stringbuilder?

723


v-model life cycle

1827


Can a top level class be private or protected?

793


What are decalarations?

852


What is unicode full form?

756


What is this keyword in java?

804


According to java operator precedence, which operator is considered to be with highest precedence?

840


What are the 2 types of java programs?

802