can you create interface instance ?
Answer Posted / tathagata
hi uday
I also tried this to call a interface of Collection and try
to instantiated but it is not working.
import java.util.*;
interface Test
{
public void wish();
}
class a implements Test
{
public void wish()
{
System.out.println("I am fine");
}
}
class Main
{
public static void main(String[] args)
{
Collection c =new Collection()
{
boolean isEmpty()
{
return true;
}
};
System.out.println(c.isEmpty());
Test t=new Test()
{
public void wish()
{
System.out.println("output:
hello how r u");
}
};
if(t instanceof Test)
{
System.out.println("t is a instance
of Test");
}
t.wish();
a oba=new a();
oba.wish();
}
}
But it is not working please explain.
| Is This Answer Correct ? | 2 Yes | 0 No |
Post New Answer View All Answers
What is the difference between serial and throughput garbage collector?
What about main() method in java ?
Why is java called java?
Is array a class in java?
What is complexity and its types?
Is it possible to override private or static method in java?
Write a program to check for a prime number in java?
What are the advantages and disadvantages of reference counting in garbage collection?
What is the do while loop syntax?
Can a class be protected in java?
Explain why wait(), notify() and notifyall() methods are in object class rather than in the reading class?
What is the common usage of serialization? What exceptions occur during serialization?
Describe what happens when an object is created in java ?
How can we make copy of a java object?
Explain about the main() method in java?