Given:
interface TestA {String toString();}
public class Test{
public static void main(String[] args){
System.out.println(new TestA()){
public String toString() {return "test";}
}
}
}
In the book, the result of this code is test.But I think TestA is an interface and you can't create an instance for TestA. Can anyone explain this to me?
new TestA() ... it's an anonymous class but there's typos around the parenthesis, should read like this: