Methods in Java
A method groups a piece of behaviour behind a name, a parameter list and a return type, and that signature is the contract callers depend on.
Declaring methods, overloading, recursion, varargs and argument passing.
5 notes
A method groups a piece of behaviour behind a name, a parameter list and a return type, and that signature is the contract callers depend on.
Several methods may share a name if their parameter lists differ, and the compiler decides which one runs before the program starts.
A recursive method calls itself on a smaller problem, and it works only when a base case guarantees the shrinking stops.
A variable arity parameter lets a method accept any number of arguments, and inside the method it is simply an array.
Java always passes arguments by value. For objects the value copied is the reference, which explains every result that looks like pass by reference.