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 hash in java?
What causes memory leak in java?
Can we clone singleton object in java?
What are thread safe functions?
Can one thread block the other thread?
What is the difference between Grid and Gridbaglayout?
Explain the difference between the public, private, final, protected, and default modifiers?
What is function overriding and overloading in java?
Is java free for commercial?
Is java a prime method?
Explain how hashmap works?
What is the static method?
Why does my function print none?
Why does java have two ways to create child threads?
Is null a string in java?