I have few questions it would be helpful if someone answered it.
What does the toString() method returns in the following code?
/** * This object (which is already a string!) is itself returned. * * @return the string itself. */ public String toString() { return this; }
As you can see the above method returns this which means the reference of the object on which it is called is returned, then if we print a String object, automatically the toString() method is called and the reference is returned to println() method ,but we are getting the output as value(Mango) not the reference (let's say the memory address would be dtt22723836@dtf).
If this (reference) is returned, then the output should be the following
String a="Mango";
System.out.println(a);
/* Actual output : Mango
My assumption :dtt22723836@dtf (as the reference is returned from toString()
to println()
*/
- what is stored in the reference variable of a String? value(Mango) or the reference(dtt22723836@dtf)?
correct me if I'm wrong. Thank you.