Passing Arguments
In this lesson, we look at the different ways to pass an argument to a method.
We'll cover the following...
Parameters of a primitive type
When a formal parameter has a primitive type such as int
, it is initialized to the value of the corresponding argument in the call to the method. This argument can be a literal constant—such as 51—or it can be a variable or any expression. This way of passing an argument to a method is known as a call by value. A method cannot change the value of an argument that has a primitive data type. Such an argument serves as an input value only.
📝 Note
The arguments in a call to a method must match the formal parameters of the method’s definition with respect to ...