You should always consider overriding the
The
You can use
which would, for a properly overridden
toString()
method in your classes.The
Object
's toString()
method returns a String
representation of the object, which is very useful for debugging. The String
representation for an object depends entirely on the object, which is why you need to override toString()
in your classes.You can use
toString()
along with System.out.println()
to display a text representation of an object, such as an instance of Book
:System.out.println(firstBook.toString());
toString()
method, print something useful, like this:
No comments:
Post a Comment