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


Please Help Members By Posting Answers For Below Questions

Highest level event class of the event-delegation model?

3486


What is stringwriter?

528


What is getkey () in java?

557


Can a class be defined inside an interface?

549


Define a package.

557






What is a qualifier in a sentence?

515


Write down program for following scenario. Use java coding standard. You have array list with some words in it..we will call it as dictionary….and you have a arbitrary string containing some chars in it. You have to go through each word of dictionary and find out if that word can be constructed with the help of chars from arbitrary string given. If you find the word print it else print none.

2271


Can we change the scope of the overridden method in the subclass?

825


What is the generic class?

517


what happens when a thread cannot acquire a lock on an object? : Java thread

530


What are the differences between c++ and java?

566


Can you override private or static method in java?

535


What are the features in java?

562


Why is the main method static?

585


What is string manipulation?

482