+ 1

What is toString method in java

plz help to understand the difference between a construct and toString in java

28th May 2018, 10:08 PM
Crispy N. Christian
Crispy N. Christian - avatar
1 ответ
0
Do you mean constructor? The toString method just outputs a string based on the object you call the method on. By default this is the class name followed by the hexidecimal memory address. It is useful to override toString for each object so that you can get information easily when debugging or printing to the console. If you did mean constructor, that's a special class member that creates an object, and can initialise fields and run code whenever an object of that type is created
29th May 2018, 7:05 AM
Dan Walker
Dan Walker - avatar