Java Java Objects Meet Objects Methods

John Hay
PRO
John Hay
Pro Student 3,478 Points

getCharacterName returns the Character Name of the string object BUT...

if the string is character name how does the getter work if Java is case sensitive?

The string characterName is not the same as CharacterName?

When using the getter we capitalise the C of character which is lowercase in the string?

3 Answers

That is how you define function name only

you start with lowercase and all other words starts with uppercase first letter

e.g.

// function
getMyName()

// variable
myName

so getMyName() is more readable than getmyName(), isnt it?

John Hay
PRO
John Hay
Pro Student 3,478 Points

So getMyName is a function which you have chosen to call getMyName. Its not using the variable myName in anyway unless we choose to use that variable as part of the function. Is that correct?

getMyName in this example should return myName variable, so in the getter you can modify return if need, that's why we don't use directly variable from class