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

mohamadreza azadi
mohamadreza azadi
5,167 Points

I need really help

this subject override toString() method right?? and Craig don't call the toString method but we see in video output has a toString method and he wont call the toString method

i'm so confused and lost i need really help

1 Answer

james south
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
james south
Front End Web Development Techdegree Graduate 33,271 Points

the toString method can be called implicitly by printing the object. in the video you see Craig compile and run example.java. at 8:03 in the previous video, we get a glimpse of example.java, and see that in main Craig instantiates a treet object, then prints a statement and fills in the treet object with the string formatter. the result is not really intelligible; this is what Craig fixes in the following video that you are asking about. by overriding the default toString method, he gets a more useful string representation of the object when example.java is run and the object is printed.