I have a base class called Items and 3 derived classes, and within the Items base class i have a print function of the form
public void print(){
Syst
It looks like overriding toString()
is more appropriate, here. You can then control the printing where it's needed, and it can go to System.out
, or a file, or a logger, and everything else.
@Override public String toString() {
return String.format("ID %s Title %s <%d> ", id, title, year);
}
Then in the child classes:
@Override public String toString() {
return super.toString() + " whatever";
}