How to use the toString method in Java?

前端 未结 13 914
说谎
说谎 2020-11-21 06:26

Can anybody explain to me the concept of the toString() method, defined in the Object class? How is it used, and what is its purpose?

13条回答
  •  失恋的感觉
    2020-11-21 07:09

    Apart from what cletus answered with regards to debugging, it is used whenever you output an object, like when you use

     System.out.println(myObject);
    

    or

    System.out.println("text " + myObject);
    

提交回复
热议问题