Can anybody explain the working of following code...?
interface myInterface{}
public class Main {
public static void main(String[] args) {
System.out.println(new myInterface(){public String toString(){return "myInterfacetoString";}});
System.out.println(new myInterface(){public String myFunction(){return "myInterfacemyFunction";}});
}
}
Output is...
myInterfacetoString
primitivedemo.Main$2@9304b1
All answers saying that myInterface in println() statement is anonymous class. But as I already declared it as an interface, why does it allow me to create anonymous class of same name....?
again...if these are anonymous classes then class main should allow me to give any name to these anonymous classes..But if try to do so..I'm getting compilation error