Hi all ,
I didn't understand the answer of the following question .Question is from John Meyers's scjp5 mock exam.
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 );
}
}
a. true false true
b. false true false
c. false false false
d. true true false
e. Compile error
Correct Answer is (b)--- false true false
Here is the 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'm particularly not getting line "since it exceeds 127."
Thanks in advance