toString method

前端 未结 2 1864
北恋
北恋 2020-12-22 06:16

I want to add a toString method in the Item class that returns the title of the item in there.

I have need make sure that the toString met

2条回答
  •  轮回少年
    2020-12-22 07:05

    Item toString:

    public String toString()
    {
      return title;
    }
    

    DVD toString:

    public String toString()
    {
      return super.toString() + " director: " + director;
    }
    

    Also, I don't know what you're trying to do with this but I would put those print() methods in these classes.

    You will be better of returning the string representation and printing it somewhere else (with this you can test this class without mocking System.out)

    Cheers

提交回复
热议问题