Menu
Question Index
...

What will be the output of the following program?

public class DataTypes {
    public static void main(String[] args) {
        int result = 0;
        short s = 42;
        Long x = new Long("42");
        Long y = new Long(42);
        Short z = new Short("42");
        Short x2 = new Short(s);
        Integer y2 = new Integer("42");
        Integer z2 = new Integer(42);
        if (x == y)    result = 1;
        if (x.equals(y))    result = result + 10;
        if (x.equals(z))    result = result + 100;
        if (x.equals(x2))    result = result + 1000;
        if (x.equals(z2))    result = result + 10000;
        System.out.println("result = " + result);
    }
}


result = 0
result = 1
result = 10
result = 11
result = 11010
Compilation Error or Runtime Error

Doubts

Problems

Topic: Creating Objects for Primitive Data Types (Byte, Short)

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App