About Question enthuware.ocajp.i.v8.2.1371 :
Posted: Thu Feb 11, 2016 6:32 pm
This question doesn't appear to have a correct answer:
Given the following declarations:
int a = 5, b = 7, k = 0;
Integer m = null;
and the following statements:
k = new Integer(a) + new Integer(b); //1
k = new Integer(a) + b; //2
k = a + new Integer(b); //3
m = new Integer(a) + new Integer(b); //4
Executed independent of each other, what will be the value of k (for //1, //2, and //3) and m (for //4) after execution of each of these statements?
The correct answer is:
12
12
12
0
However, this answer isn't one of the choices. The test says that this is the correct answer:
12
12
12
12
But the last one can't be 12, as statement 4 doesn't affect the variable k, and the instructions say that each statement is independent of the others. Therefore, k would still be 0.
Given the following declarations:
int a = 5, b = 7, k = 0;
Integer m = null;
and the following statements:
k = new Integer(a) + new Integer(b); //1
k = new Integer(a) + b; //2
k = a + new Integer(b); //3
m = new Integer(a) + new Integer(b); //4
Executed independent of each other, what will be the value of k (for //1, //2, and //3) and m (for //4) after execution of each of these statements?
The correct answer is:
12
12
12
0
However, this answer isn't one of the choices. The test says that this is the correct answer:
12
12
12
12
But the last one can't be 12, as statement 4 doesn't affect the variable k, and the instructions say that each statement is independent of the others. Therefore, k would still be 0.