describe tostring methods print methods are


Describe toString() Methods ?

Print methods are general in some languages, but most Java programs operate differently. You can use System.out.println() to print any object. Therefore for good results your class should have a toString() method which formats the object's data in a sensible way and returns a string. Otherwise all that's printed is the name of the class that is generally not what you need. For instance, a good toString() method for the Car class might be

public String toString() {
return (this.licensePlate + " is moving at " + this.speed
+ "kph and has a maximum speed of " + this.maxSpeed +"kph.");
}

Request for Solution File

Ask an Expert for Answer!!
JAVA Programming: describe tostring methods print methods are
Reference No:- TGS0284735

Expected delivery within 24 Hours