Hi,
I'm preparing for
SCJP 5 and while solving a mock question paper encountered this question:
class
test {
public static void main(String[] args) {
test inst_test = new test();
int i1 = 2000;
int i2 = 2000;
int i3 = 2;
int i4 = 2;
Integer Ithree = new Integer(2); // 1
Integer Ifour = new Integer(2); // 2
System.out.println( Ithree == Ifour );
inst_test.method( i3 , i4 );
inst_test.method( i1 , i2 );
}
public void method( Integer i , Integer eye ) {
System.out.println(i == eye );
}
}
Answer: The correct answer is false true false.
Explanation: lthree and lfour are two seperate objects. if the lines 1 and 2 were lthree = 2 and lfour = 2 the result would have been true. This is when the objects are created in the pool. When the references i and eye in the pool are compared 2==2 results in true and 2000==2000 is false since it exceeds 127.
I couldn't understand that 2000==2000 is false since it exceeds 127. What's there with 127? Is it that objects created in pool doesn't accept the value above 127?
Also, suggest some links for mock exams.
Please help!
Thanks.