CJCoding With Joseph
15per day
← Back to Question List
Java Code Walkthrough #29

Two Variables Point To The Same Array

mediumVariables

📄 Code

Read carefully — what does this print?
1import java.util.Arrays;
2 
3public class Main {
4 public static void main(String[] args) {
5 int[] a = {2, 4, 6};
6 int[] b = a;
7 
8 a[1] = 9;
9 b[2] = a[0] + a[1];
10 
11 System.out.println(Arrays.toString(a));
12 System.out.println(Arrays.toString(b));
13 }
14}

🎯 Your Answer