can you create interface instance ?
Answer Posted / mallesh
hey uday that is not creating intance for Test interface ,
ur implementing the interface using anonymous class
(unknoun class)
public class Test2 {
public static void main(String[] args) {
Test2 t=new Test2();
Runnable r=new Runnable() {
public void run() {
System.out.println("Hi");
}
}; r.run();
System.out.println(r.getClass().getName().toString());
System.out.println(t.getClass().getName().toString());
}
}
Output:Hi
Test2$1
Test2
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
What is difference between wait and notify in java?
How many bits is a boolean?
Can we define static methods inside interface?
When will we use them?
Do you know why doesn't the java library use a randomized version of quicksort?
Given a singly linked list, how will you print out its contents in the reverse order? Can you do it with consuming any extra space?
Is array serializable java?
What is an argument in java?
What is string [] args?
What are keyboard events?
Explain about public and private access specifiers?
What is a dot notation?
What are the two types of exceptions in java? Which are the differences between them?
Is object a data type in java?
What is parseint?