I am new to java. I had a doubt.
class ArrTest{
public static void main(String args[])
{
int i = 0;
int[] a = {3,6};
a[i] = i = 9;
System.out.println(i + " " + a[0] + " " + a[1]); // 9 9 6
}
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This is another good example the great Java evaluation rule applies.
Java resolves the addresses from left to right.
a[i]which is the address ofa[0], then i which is the address of i, then assign 9 to i, then assign 9 toa[0].IndexOutOfBoundsExceptionwill never be throw sincea[0]is not out of bound.The misconception is
a[9], which is against the left-to-right-rule