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

Bryan Martinez
Bryan Martinez
2,227 Points

Question about creating a new cow object

When I did the exercise I used this Cow larry = new Cow("Larry");

Does it matter that I did not use "cow" instead of "larry" Cow cow = new Cow("Larry");

Can the object be named anything?

4 Answers

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hi Bryan,

Yes, as with any variable, the name can be anything. It is a good idea, though, to keep them logically named. For example, you wouldn't want to create a new Cow object named myHorse... :smirk: But otherwise, whatever you deem appropriate to name them is just fine.

:) :dizzy:

It is a variable so it follows the rules for naming variables but yes you can name it larry.

alastair cooper
alastair cooper
30,617 Points

The name of the instance is 'cow', but the Cow presumably also has a member variable called name which you are assigning the string 'Larry' when you initialise it. These 2 'name' variables are different things. If the cow has a getName() method, it will return 'Larry', but you refer to the object with the name 'cow'

Bryan Martinez
Bryan Martinez
2,227 Points

Thank you guys for answering my question. You guys are great!