Menu
Topics Index
...
`

Integer wrapper


If you need explanation Read this topic

If you need Answer Take test on this topic

Integer wrapper
What will be the output of the following program?
public class Compare
{
    public static void main(String[] args)
    {
        Integer i1 = 1;
        Integer i2 = 1;
        System.out.println(i1 == i2);
        
        Integer i3 = -200;
        Integer i4 = -200;
        System.out.println(i3 == i4);
    }
}

A. true
true
B. false
false
C. true
false
D. false
true
E. Compilation Error or Runtime Error
Topic: Creating Objects for Primitive Data Types (Byte, Short)

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

Ans is C..here we have concept of the Wrapper classes,some times we need to use Objects instead of the primitives for that java provides classes for the every primitive type

Execution:
here we create the reference for the Integer class and assigned with the 1, here 1 is primitive which will automatically convert to the object this process known as the "auto-boxing" and again we create another reference and assigned with the 1 and next we are comparing the the references so it will return true next we are assigning the negative values as -200 here it will return false

Posted by Uday Kumar    2015-02-26 09:35:12


c

Posted by Shubham Bansal    2015-02-26 19:14:11


Answer is c

Posted by Shashanka Mogaliraju    2015-02-27 03:02:10


This dose is now closed and the winners are Uday Kumar,  for 'First Correct Comment' and Shashanka Mogaliraju for the 'Popular Comment'. The 'lucky liker' is Sai Ram. Please login into Merit Campus using facebook, to claim your recharge. Go to http://java.meritcampus.com/earnings to raise the recharge.

Posted by Merit Campus    2015-02-27 03:22:41


© meritcampus 2019

All Rights Reserved.

Open In App