- 2
How value types are different to reference types?
Why doesn't it print the incremented value, is it predefined that value types will not be incremented and if it is why is it so?
4 odpowiedzi
+ 1
public class MyClass {
public static void main(String[ ] args) {
int x = 5;
int y = addOneTo(x);
System.out.println(y);
}
static int addOneTo(int num) {
num = num + 1;
return num;
}
}
Try to run this code.
After making some enhancements you will see that it prints incremented value.
+ 1
Now as you read value type only affect the value of the variable but using reference type will affect the value at the memory of the variable.
Value type is like working one particular value while reference type is working on the memory, reference point of the variable.
0
So no answers?
0
Thanx