+ 2
value type but it affects the same as object
public class MyClass { static void addOneTo(int num) { System.out.println(num + 1) ; } public static void main(String[ ] args) { int x = 5; addOneTo(x); } } can anybody explain it's value type but it affects by the method addOneTo(x)
3 Antworten
+ 17
the code is fine & will work ☺
//method ::: addOneTo ()
//parameter ::: x
//output ::: 6
+ 15
method is addOneTo //see last line u typed @nour
+ 3
5 is passed to the method addOneTo();
So, num is 5.
So, 5 + 1 is printed.
Pass by values means num and x are independant.
If I increment num, x will not be incremented too.