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
How can you traverse a linked list in java?
Difference between final and effectively final ?
What is a java list?
What is difference between throw and throws ?
What is a nested list?
What is consumer in java?
Explain runtime exceptions?
Write a program to find the whether a number is an Armstrong number or not?
Differentiate between overriding and overloading cases?
What is void keyword?
What are the java ide’s?
What is a protected class in java?
What are alternatives to java serialization?
Is java se free?
What is the meaning of immutable regarding string?