Wrapper Class Vs Primitive types Output 1
public class Tester {
public static void main(String[] args) {
Integer sum1 = 125; //line 1
int sum2 = 125; //line 2
System.out.print(sum1.equals(sum2)); //line 3
System.out.print(sum2.equals(sum1)); //line 4
System.out.print(sum1==sum2); //line 5
}
}
Output:
1. Compilation error at line 3
2. Compilation error at line 4
3. truetruefalse
4. truetrueture
public static void main(String[] args) {
Integer sum1 = 125; //line 1
int sum2 = 125; //line 2
System.out.print(sum1.equals(sum2)); //line 3
System.out.print(sum2.equals(sum1)); //line 4
System.out.print(sum1==sum2); //line 5
}
}
Output:
1. Compilation error at line 3
2. Compilation error at line 4
3. truetruefalse
4. truetrueture
For Explanation Please leave comments
ReplyDelete