Overriding toString method

后端 未结 7 511

I am using .toString to return a string representation of an object, i.e.

jcb.engineMove(move.toString());

will produce e2e4.

What

7条回答
  •  我在风中等你
    2020-12-12 06:03

    1. I would probably not use toString() in this case because it appears that you are simply repeating the logic that is in the Move class. In order to add any other details, I have one question: to what class are you adding this toString() method?

    2. You call this method just like any other method. First you need an instance of an object to call it with:

      someObj.toString();

    To give any more details, I need an answer to the previous question.

提交回复
热议问题