Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Java Data Structures - Retired Getting There Object Inheritance

printf() calling the toString() confusion:((

Hello,

So it took me some time to figure out the the printf() in the main() naturally calls the toString() and that is why we indeed had to override it. It seems like this important information had been left out (if I just missed it please point me to where in the video it was explained)

To the point, I know that toString() takes a parameter and turns it into a String. However, in the printf() we already pass a String in quotas. So why do we need quotes then if it will call the toString() anyway? Since the beginning of the course we have been taught to place our System.out.println() messages in quotes.

Thank you for your answers!

1 Answer

Steven Parker
Steven Parker
231,269 Points

:point_right: Quotes identify a literal string.

Without the quotes, the words of your literal string would be mistaken as variable names or language keywords.

The implicit toString conversion only applies to variables.

That's what I always thought. Then how does this toString() method that we override gets called in our main?