Parameters and Return Types in Methods
In this lesson, an explanation of how to pass parameters to the methods is explained.
We'll cover the following
Methods take in two types of parameters. One is the primitive data type and the other is the reference data type. We will be looking in detail at both types of parameters and how each of them is used for a different purpose.
Primitive type
These types of parameters are said to be passed by value. The value from the calling method IS copied to a variable in the called method. What this signifies is that once a parameter is passed or given to a method as an argument, there is no relation between the object i.e. the parameter that is present outside the method body, and the modification that is happening inside the method to that parameter. This can be a bit hard to understand.
The code and diagram below explain this concept.
Get hands-on with 1400+ tech skills courses.