+ 1
The name of getter and setter
An I correct that I am free to decide on my own the names of my getters and setters? Now the tutorial is teaching me to name my getter âgetVarâ capitalizing the first character of the variable, and similarly for setter. But what I see is that it is just a new method defined. It is the âreturn Varâ and âVar = âŠâ defined under those methods that do the job. Are there any reason to stick to that particular naming style?
1 Answer
+ 5
Exactly. Common misconception of getters and setters is that they need to be named get/set. They don't have to be, Now, on that note, it is best to put some variation of get and set in the method name so YOU and anyone reading the code knows what those methods are doing. Also, common Java practice to name variables camelCase. Also other etiquettes exist for other things too.