Joel Mata wrote:Hi all, need some help understanding How "Test" is written in output. That is, i dont know how is toString called.
Thanks in advance!
interface TestA { String toString(); }
public class Teste {
public static void main(String[] args) {
System.out.println( new TestA() {
public String toString() {
return "teste";
}
});
}
}
Hi Joel,
I think the question is about toString() rather than inner classes.
You are implementing the interface TestA and overriding the toString() in an anonymous Inner Class inside printlnO() method
If you override public
String toString() method, that will be printed when you print the class like new
Test().
Please see the code below, i have taken your code and added couple more examples
hope this clears the question!
SCJP6, SCWCD5, OCP-JBCD5, OCE-JWSD6 OCE-JPAD6 , OCM-JEA5 1,OCM-JEA5 2,3,OCJP8 - Brainbench certifications: J2EE, Java2, Java2-NonGUI, JSP, SQL2000 Admin, SQL2000 Programming , Brainbench certified Java Programmer, Computer Programmer, Web Developer, Database Administrator