The <Object>.toString function is used to represent an object as a String.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
class Circle {
  private int radius;

  public Circle(int radius) {
    this.radius = radius;
  }

  @Override
  public String toString() {
    return "Circle with radius " + radius;
  }

For more complicated concatenations, you may prefer to use the String.format(format, ...args) static method.

For example:

1
2
3
4
5
6
// ...

  @Override
  public String toString() {
    return String.format("Circle with radius %dcm, colour %s", this.radius, this.colour);
  }