You can always override toString()
:
@Override
public String toString(){
return "This Object";
}
All Classes in the Java Platform are Descendants of Object, which is why any object of any class (even the ones you create) has access to Object's toString()
method defined as follows:
public String toString(){
getClass().getName() + '@' + Integer.toHexString(hashCode());
}
toString()
gets called by default when you call System.out.println()
but its just a regular inherited method and there is nothing stopping you from freely overriding it.
See this explanation on Oracle's website.