What is the result of the following program?
1: public class Main { 2: public static long square(int x) { 3: long y = x * (long) x; 4: x = -1; 5: return y; 6: } 7: public static void main(String[] args) { 8: int value = 9; 9: long result = square(value); 10: System.out.println(value); 11: } 12:}
B.
Java is pass-by-value and the variable value never gets reassigned.
public class Main { public static long square(int x) { long y = x * (long) x; x = -1; return y; } public static void main(String[] args) { int value = 2; long result = square(value); System.out.println(value); } }