Isn't the result supposed to be 6?
Code :
public class Examp {
public static void main(String[] args) {
int i = 5;
Examp examp_object = new Examp();
examp_object.inc(i);
System.out.println(i);
}
public void inc (int k) {
k++;
}
}
For my surprise, the result is appearing to be 5. Why is that?
Re: Isn't the result supposed to be 6?
What do you mean by "result"?
Remember that variables are passed to methods by value. The method inc can only change its copy of the variable, not the source of the value.