xxxxxxxxxx
@Override
public String toString() {
String s;
return s;
}
xxxxxxxxxx
// toString returns a String, so can't return printf or System.out.print
@Override
public String toString() {
return String.format("% is traveling at % mph", getName(), getSpeed());
}
xxxxxxxxxx
import java.util.*;
class Kid {
String name;
double height;
GregorianCalendar bDay;
public Kid () {
this.name = "HEAD";
this.height = 1;
this.bDay = new GregorianCalendar(1111,1,1);
}
public Kid (String n, double h, String date) {
// method that toString() can't find somehow
StringTokenizer st = new StringTokenizer(date, "/", true);
n = this.name;
h = this.height;
}
public String toString() {
return Kid(this.name, this.height, this.bDay);
}
} //end class
xxxxxxxxxx
@Override
public String toString() {
// Customize the implementation of the toString() method
// to return a meaningful string representation of the object
// For example:
return "This is a custom toString() method override";
}