119k views
4 votes
What is output by the following code?

public static void stuff(int w) {
w -= 2;
}

public static void main(String a[]) {
int n = 2;
stuff(n);
System.out.print(n);
}


1. 0
2. 4
3. 1
4. 3
5. 2

1 Answer

6 votes
The output is 2. The stuff() function receives a copy of n, changes it but the result is never used.
User OJay
by
8.5k points