can you create interface instance ?

Answer Posted / akthar

No,we can't create an object to an interface...as told uday he create a anonymous class same as Test interface ..if we remove the interface and method it is working ....so t doesnot act as object to an interface it acts as an anonymous class object...so it invoking its anonymous method..

class Main
{
public static void main(String[] args)
{
Test t=new Test()
{
public void wish()
{
System.out.println("output: hello how r u");
}
};
t.wish();
}
}

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How can you traverse a linked list in java?

653


Difference between final and effectively final ?

610


What is a java list?

560


What is difference between throw and throws ?

574


What is a nested list?

497






What is consumer in java?

503


Explain runtime exceptions?

711


Write a program to find the whether a number is an Armstrong number or not?

555


Differentiate between overriding and overloading cases?

572


What is void keyword?

640


What are the java ide’s?

553


What is a protected class in java?

513


What are alternatives to java serialization?

579


Is java se free?

503


What is the meaning of immutable regarding string?

491