0
Can someone give me brief description of how this example works
I am a beginner in programming world. I was going through the java course here, at this point I got stuck because I don't know how the output of the following example is 5. Can someone please explain to me how this example actually works? public class MyClass { public static void main(String[ ] args) { int x = 5; addOneTo(x); System.out.println(x); } static void addOneTo(int num) { num = num + 1; } } // Outputs "5"
2 Réponses
+ 3
It is happened because you pass copy of varible x in your method. Therefore initial value is not changed
+ 3
I had tried my best to explain it here.
Hope this helps☺️☺️.
https://www.sololearn.com/Discuss/1406887/?ref=app