After execution of the code fragment below, what is the value of a[b]?
package net.dharmaraj;
public class dev {
public static void main(String ar[]) {
int[] a = { 10, 22, 33 };
int b = 1;
a[b] = b = 0;
a[b] = b = 1;
System.out.println(b);
System.out.println(a[1]);
a[b] = b = 2;
System.out.println(a[1]);
a[b] = b;
System.out.println(b);
System.out.println(a[b]);
}
}
Choose answer(s)
a) 1
b) 0
c) 3
d) 2
Ans:-
Hint:-
// due to operator precedence 1st it will execute script ,2nd it will
// execute asignment operator.
Output:-
1
0
2
2
2
No comments:
Post a Comment