In
java, the argument is passed to method call using passed by value only. Hence, a copy of variable is passed to the method called, so any change in this copy, will not have any effect on the original variable.
In the given example, the variable name i in the method fermin used to create confusion only. Actually this varible i is the local copy of the method and hence its scope is limited to the method only. It just hold the copy of value passed by the method call and hence no relation with the i in main method.
Mukesh
Originally posted by sangeeta chaudhary:
What will be the o/p of this code ???
public class Inc{
public static void main(String argv[]){
Inc inc = new Inc();
int i =0;
inc.fermin(i);
int y = i++;
System.out.println(y);
System.out.println(i);
}
void fermin(int i){
i++;
}
}
answer is 0 . Why???