From the course: Java SE 21 Developer (1Z0-830) Cert Prep

Unlock this course with a free trial

Join today to access over 25,600 courses taught by industry experts.

Question deep dive

Question deep dive

- Now, let's dive in and take a look at a question that is reasonably similar to the kind of thing you'll find on the exam. Let's see how this would evaluate. We start out with the value of i is 1, but then in here where we perform the assignment, we pre-increment i before we use it as the array subscript. That means at this point that i is actually equal to 1, not 0. As a result of that, that reference refers to that second element, subscript 1 of the array. So, that's where the assignment is going to happen, evaluating our operands from left to right. The next operand to be evaluated will be this one, ia = ++i again. Well, the ++i will pre-increment i, so i is now 2 and that means that the ia here refers to this element of the array. Then we move further to the right and we come across ia subscript i. Well, i has not been changed by this operation, so we are left with the same I = 2 in this case, which means…

Contents