Section 7e

Methods - Calling and Being Called


 

 

 

 

 

 

 

 

 

 

 

 

Calling and Being Called

Simple, but important terminology.

There are just a couple more terms to get familiar with since they are commonly used when discussing the use of methods. When you write the multiplication method operation in the main method, you are asking it to multiply the two numbers and return the result to your variable product. At that point, it is said that you have called the method, and the main method (in this case) is termed the calling method.

The multiplier method that was called upon to conduct its duties is termed the called method. Any method can call any other method in a program with one exception; the main method is not called by any other methods; this is discussed next. However, because you will be working with methods calling other methods (a lot!), you need to become familiar with these terms. The calling method is the one that calls or asks another method to do something. The called method is the method that has been called or asked by another method to do something.

The other term with which you need to become familiar is related to how data is passed to the called method. When you pass two values to a multiplier method, or one value to a factorial method, your calling method is said to pass a copy of the value to the method. This process is called, believe it or not, pass by copy. It is not complicated but it is important to know. Since you are passing a copy of your parameter value, the method can change the copy or use or manipulate it as it needs to, and no change will come to the original value passed by the calling method. While this makes pretty good sense, it will become more important later on.

Watch this video for some further support on both methods using pass by copy and methods being passed a string class object. Once again, you should practice the code you see at least two or three times to get fluent with it.