Calling Methods

Calling a method means starting to execute the code, which is in the body of the method. This happens by writing its name, followed by parentheses () and the sign ; to end the row. If the method needs input data, it is given in the parentheses (), and the succession of the parameters should be the same as the one of the given parameters when declaring the method. Here is an Example:

A method can be invoked from several places in the program. One way is to call it in the main method.

A method can also be called from the body of another method, which is not the main method of the program.

There is also a possibility for the method to be invoked in its own body. This is called recursion and you can find more information about it in Wikipedia or you can search on your own in the Internet.

It is important to know that if a method is declared in a class, it can be invoked before the line, on which it has been declared.

results matching ""

    No results matching ""