Hey all,
I'm working on a programming assignment for school. The whole thing runs just as intended, so I don't need help with any of the coding. But I do have a question as to why something works the way it does.
Synopsis:
I constructed 2 classes that take four integer arguments and store them. The first is EarthTime which accepts Minutes, Hours, Days, and Years. The second is an alien time, PsarTime, which accepts Sparens, Cies, Cromas, and Asurs. The latter units convert differently than EarthTime, and the task was to make functions for each class that can convert each time and add and subtract them in anyway, after which units are reduced to the lowest common factors (signs being preserved). Anyway, that's not the important part.
To output to console, I called
Code:
System.out.println(EarthTime1);
(EarthTime1 is an instance of class EarthTime).
Previously in the class I had constrcuted a String toString() method as follows
Code:
public String toString(){
String time;
time = this.getYear() + "Y:" + this.getDay() + "D:" + this.getHour() + "H:" + this.getMinute() + "M";
return time;
}
Anyways, running the print to console method, I was suprised to see that it printed following the rules of the toString() method that I had defined even though I had not called toString() anywhere in the execution, nor in any other methods (outside of defining the method itself).
Does it just replace the java .toString() method? I'm curious if anyone can clue me in as to why it is behaving this way. Again, this is the desired result, I'd just like to understand why it happened. Thanks!