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

Popular posts from this blog

1111. appearing after print sequence - php -

node.js - Express and Redis - If session exists for this user, don't allow access -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -