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 trialBryan Martinez
2,227 PointsQuestion 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
Treehouse Moderator 145,860 PointsHi 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
... But otherwise, whatever you deem appropriate to name them is just fine.
:)
KRIS NIKOLAISEN
54,971 PointsIt is a variable so it follows the rules for naming variables but yes you can name it larry.
alastair cooper
30,617 PointsThe 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
2,227 PointsThank you guys for answering my question. You guys are great!