Construction. Methods
[comp1110-83]
Construction. Methods
[comp1110-83]So far, we have sometimes written code in separate functions from the main function.
But in every case so far, we had to give those functions all the arguments that they were supposed to work with.
Methods defined in a class implicitly have access to the fields defined in that class. This is because methods always need to be called on a specifc object, whose field values can then be used within the method.
So in principle, writing a method is just like writing a function, except inside a class. Within the class, you can all other methods within the class just like we called functions before.
By convention, in Java, method names are camelCased.
That is, they start with a lower-case letter and otherwise contain only letters and digits,
with uppercase letters indicating the start of a new combined word, as in sumOfAllParts.