Question: # Java I have some question about static and array: For example, in the first case: The list won't reverse. But in the second case:

# Java

I have some question about static and array:

For example, in the first case: The list won't reverse.

But in the second case: the numbers[0] is 3, the value of 3 is transfer from the static method m.

why ??

Case1:

public class Test { public static void main(String[] args){ int[] list = {1,2,3,4,5}; reverse(list); for(int i=0; iout.println(list[i]+ " "); } } public static void reverse(int[]list){ int [] newList = new int[list.length]; for(int i=0; i 

__________________________________________________

Case2: public class Test { public static void main(String[] args){ int number =0; int[] numbers = new int[1]; m(number, numbers); System.out.println("number is :"+ number+" and numbers is :"+ numbers[0]); } public static void m(int x, int[]y){ x = 3; y[0] = 3; } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!