In each class definition there is a built-in instance method called
toString(). The return type of this method is String. The body of the
method contains a return statement in which we place the string we want
returned. In order to use this method, we simply place the name of the
object as an argument to System.out.println.
For example, in our Room.java program we have the following.
public class Room {
...
public String toString() {
return( ... );
}
...
}
In order to use this method in our Hotel.java, we could do the following.
public class Hotel() {
...
theRoom = new Room(10,10);
...
System.out.println(theRoom);
...
}