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
What do you understand by garbage collection in Java? Can it be forced to run?
What are wrapper classes in java?
How does thread synchronization occurs inside a monitor? What levels of synchronization can you apply?
what are Hostile Applets?
How to perform quicksort in java?
Is a boolean 1 bit?
What is a singleton factory?
Does every java program need a main?
How can constructor chaining be done by using the super keyword?
Can we create a constructor in abstract class?
What is the formula to calculate percentage?
Is null in java?
Does java runtime require a license?
Why runnable interface is used in java?
What is java and why do we need it? Explain