0
Can someone explain the function of a toString is and why it's necessary in Java?
Java
2 Answers
+ 2
The toString() in Java is used to represent objects in terms of strings. Whenever you try to print an object in Java, it will print 'className@hashCode' which is not a readable format so it is good to override the toString() in your class so that the content becomes more readable.
Zoe run the code with and without the comments and you will understand.
https://code.sololearn.com/c2ObrHJOrv1z/?ref=app
+ 1
Okay that makes sense thank you Avinesh