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 The Challenge

Object comes out to "null"

Every time I try to print the name, it comes out to "null." Not sure how to fix it.

https://w.trhou.se/pixaufo6nj

1 Answer

Steven Parker
Steven Parker
231,184 Points

On line 8 of Cow.java, you have name = "Camille"; which just overwrites the parameter instead of setting the class property (leaving the property "null"). Plus, it always sets the name "Camille" instead of the argument that was given.

In the video, the code shown for that line is this.name = name; which sets the property using the parameter.

You might want to review this part of the video.