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 trialAditya Puri
1,080 Points2 questions
SO I have 2 questions?-
1) Is including the keyword "get" in front of getter methods a naming convention or is it an essential part of the syntax?
2)How can a java tell the difference between a class field variable and a method? Both of them start in the same way which is- (public/private) (output datatype) (name) .
2 Answers
markmneimneh
14,132 PointsHi
1) Is including the keyword "get" in front of getter methods a naming convention or is it an essential part of the syntax? Generally speaking, Yes ... it is a convention, that you should stick with it.
There is nothing stop you from creating a method called "GrabIt" and writing your own code to deal with it ... then you loose all IDE support and users of your code would have no idea what you are doing ... again I advise stick with the convention.
2)How can a java tell the difference between a class field variable and a method? Both of them start in the same way which is- (public/private) (output datatype) (name) .
public/private defines who can access the targeted item.
A field can be private or public
and
A method can be private or public
java is not going to get confused because where as a field is defined as in: private String myString; or public String myString;
a method would have a different syntax private String myMethod(){ } or public String myMethod(){ }
hope this helps. If this answers your question, please mark the post answered.
Thanks
Alexander Kobilinsky
359 PointsCaleb Christopherson
3,204 PointsWhy do you post that everywhere??
Aditya Puri
1,080 PointsAditya Puri
1,080 Pointsoh, ok thanks!!