What result will give this code:

int []a = {5,5};
int b = 1;
a[b] = b = 0;
System.out.println(Arrays.toString(a));
Explanation
Order of operations is next:
1. Index of array a to be assigned is determined - a[1]
2. b is assigned to zero
3. a[1] is also assigned to zero

Why is a[1] and not a[0] is assigned? When does the JVM resolve the a[b] reference to a memory address?

2018 Nov 30, 6:12:59 PM

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
Java quizzes
Cosmo
Sign Up Now
or Subscribe for future quizzes