Method Parameters (Arguments)

description of image


Method Parameters


We can also pass values to a method. These values we pass to a method are known as arguments.

Let’s take an example,



Return a Value


Let’s modify the addNumbers() method we have been working on so that it returns a value.

Things to Notice in below program

Before, the return type of the method was void. It means the method didn’t return any value.

Now, the return type is int. Meaning, the method must return an int value.

To return the value, we have used the return statement: return sum;



Quiz


Question Text