0
What means addOneTo?
In the Value Types, addOneTo is (perhaps) a method. If addOneTo means you add 1 at integer "num", why the integer is remains 5? (The integer is 5) https://www.sololearn.com/discuss/68786/?ref=app https://www.sololearn.com/discuss/784112/?ref=app
1 Odpowiedź
+ 1
In Java, variables are passed to functions by value and not by reference. So by doing
static void addOneTo(int num) {
num = num + 1;
}
and then calling the function:
int num = 1;
addOneTo(num);
The value of x is incremented by 1 only within the scope of the function. The variable "num" which is outside the scope of addOneTo still remains as 1, unchanged.