Test Killer 310-065 for SCJP (Java) -


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 book, result of code test.but think testa interface , can't create instance testa. can explain me?

new testa() ... it's anonymous class there's typos around parenthesis, should read this:

interface testa {string tostring();} public class test{   public static void main(string[] args){      system.out.println(new testa(){         public string tostring() {return "test";}      });   } } 

Comments