Hello, Could you explain to me why in the OOP: Books task the System.out.println(books) method returns the value of getOutputByBookType() if this is not called? thank you
Why the System.out.println(books) method returns the value of getOutputByBookType()
You must be signed in to leave a comment
28 November 2022, 11:37
Polymorphism. When an object is passed to PrintStream.print/println, this method calls the toString method. Usually it is defined in Object. If you override the toString method in a descendant (and Book is a child of Object), the method of the descendant is used.