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


Please Help Members By Posting Answers For Below Questions

What is the importance of hashcode() and equals() methods?

570


What is array class in java?

587


Can size_t be negative?

604


How do you identify independent and dependent variables?

498


Can a class be protected in java?

491






Explain about the interpreter in java?

617


How many ways can we create singleton class?

492


What is a class object?

492


What is difference between filereader and bufferedreader?

523


Explain the importance of thread scheduler in java?

588


Why does java doesnt suuport unsigned values?

1788


What is a byte string?

609


What are parsing rules?

493


What is oops in java?

556


How does remove work in java?

513