+ 2

Help!!!What is toString()

public String toString(){ }

2nd Feb 2017, 7:09 AM
yakuza
yakuza - avatar
7 ответов
+ 4
in c++ it converts the input value to a string. dare say java does the same. but i dont java.. keeps me up all night. someone else can explain what it means in java
2nd Feb 2017, 7:18 AM
jay
jay - avatar
+ 4
toString() is a method to return a String object representing any value that is passed to it
2nd Feb 2017, 8:13 AM
Deddy Tandean
+ 3
Let's say you want to create a Person class. Person owns the attributes name, age and whatever you can think of. Now try to print an instance of person. There will be an obscure output on the console (object id @ hash code of the object). That is usually not what you want, right? So you can override the toString method of your class. In toString you can create your own return string.
4th Feb 2017, 8:07 PM
Tashi N
Tashi N - avatar
+ 2
aiiiiii!!!!! sololearn and you guys make me happy😊😊.thank you guys!
2nd Feb 2017, 7:24 AM
yakuza
yakuza - avatar
+ 1
thanks, you learned me something about c++.
2nd Feb 2017, 7:20 AM
yakuza
yakuza - avatar
0
thanks @deddy Tandean you guys are awesome.
2nd Feb 2017, 8:16 AM
yakuza
yakuza - avatar