Object-Oriented Programming
(Part II)
Methods
Methods contain the logic that provide an object with behavior. A method
declaration contains a list of modifiers,
a return type, a method name, a list
of parameter types
and their corresponding names, and a list of throwable
exceptions. A method signature is the combination of the method name as well
as the types and order of its parameters. Note that
the names of parameters are
not included in the method signature.
A method can invoke itself in a process called recursion. Recursion is an
alternative to looping that provides an elegant solution for problems that
naturally repeat, such as mathematical sequences
or divide and conquer
algorithms. A recursive method must have a termination condition that
determines when the method stops calling itself and starts returning values
to previous invocations on the call stack.
A recursive method with
no termination condition will eventually cause a StackOverflowError.