String myString="Plz_help";
I came to know that ‘myString’ is not an object but a object reference variable which stores the base address of the actual object. So ‘myString’ should return an address when i execute
System.out.println(myString);
but it is returning ‘Plz_help’ to the output.
Myclass obj_ref_var=new Myclass();
When I use the same System.out.println(obj_ref_var) for other class which I had created, it is returning the address.
When you call
System.out.printlnon an object reference, system executestoString()method defined for the actual object that this reference refers to. ForStringthis method returns its value.Apparently, you haven’t defined
toString()method for your class that’s why you get object classname + hashcode.