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
Riccardo
Level 29
Why the System.out.println(books) method returns the value of getOutputByBookType()
Under discussion
Comments (1)
- Popular
- New
- Old
You must be signed in to leave a comment
Thomas
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.
0