Understanding methods
Now, I must admit that I have been coding since 1980, and since then, the term we use to describe discrete blocks of code has changed. When I started coding in 1980 using BASIC, an unstructured language, I quickly learned to break my code up into subroutines. From BASIC, I moved on to Pascal, where there is a formal designation for blocks of code. These were functions for blocks that returned a result and procedures for blocks that did not return a result. Next up was C, followed by C++. These languages name their blocks of code as functions, as they all, except for the constructor, must return a value. Moving on to Java, these blocks are called methods. Let us examine the components of a method.
When creating a method, you will need to consider some or even all of these components:
- Access control designation
- Static or non-static designation and the
this
reference - Override permission
- Override required
- Return type
- Method name ...