What will the following program display?
public class ChangeParam { public static void main(String[] args) { int x = 1; double y = 3.4; System.out.println(x + " " + y); changeUs(x, y); System.out.println(x + " " + y); } public static void changeUs(int a, double b) { a = 0; b = 0.0; System.out.println(a + " " + b); } }
The program will display the values that are given below:
1 3.4
0 0.0
1 3.4
Explanation:
The given program will return above values that can be defined as:
In the program, we define a class that is "ChangeParam" in this class we define main method in the main method we define two variables that are "x and y" variable x is an integer variable that assigns value 1 and variable y is a double variable that assigns value 3.4. and we will print the variable value.
Then we call the changeUs() function. In this function, we pass x and y local variables. In this function, we pass two variable that is "a and b" as a parameter and assign value 0 and 0.0. that's why it will prints "0 0.0" value.
After calling changeUS() function we print the local variable "x and y" values that are 1 3.4.