JavaChallenge42

Govinda Raj
wolfie/JavaChallenge
2 min readOct 8, 2021

--

Try to solve the challenge by yourself first!

I got surprised when I saw the bytecode of the above code —

Before understanding the bytecode, let me tell you the answer which is —

Yes, that’s what the answer is. So this challenge is on Java Precedence. Let’s see that —

There are three operators- [], =, = as —

So according to the precedence table arr[index] has become arr[0] because currently index=0; Now there are 2 = so which one will be evaluated first? So we can get that info from the precedence table itself. In case of = operator the evaluation happens from Right to Left, so now index=3 evaluated first and now the value of the indexis 3 which will be assigned to arr[0] . The value arr[3] is 0 which is a default value of primitive int.

--

--

Govinda Raj
wolfie/JavaChallenge

Senior Software Developer. Tech Enthusiast and love coding. My portfolio: https://govinda-raj.github.io/