Specifying a method's parameters

If you look up the word "parameters" in the dictionary, your brain will probably seize up. All it means is that the method has to be able to use the information you send it, so you simply have to specify the type of data that the method is allowed to use. That's it! It's very simple.

In the earlier screenshot, on line 23, we declared the firstNumber and secondNumber variables. The type is int. Now notice our member variables: number1, number2, and number3. They are also of the int type. These variables have to be of the int type since they store the numbers that will be added in the method, which the parameters specify will be of int the type.

So now, go look in the dictionary again. You will probably see the word limit in there somewhere. That's what you did when you specified the type of data that the method will use, an integer in this case. You set some limits on what is allowed.

Okay, so you're setting parameters, or limits, on the type of data the method can use, but what exactly is a parameter? Well, the first parameter is called firstNumber. And what is firstNumber doing? It stores a value that will be used in the code block on line 25. What do we call things that store data? That's right, variables! Variables are used everywhere.

Note

Remember that a variable is just a substitute name for the value it actually stores.

As you can see on line 25 of the code block, those variables are being added and stored in the result variable.

How many parameters can a method have?

We can have as many parameters as we need to make a method work properly. Whether we write our own custom methods or use the methods of the scripting reference, the parameters that are defined are what the method will require to be able to perform its specified task.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset