Menu
Topics Index
...
`

Enumeration and Autoboxing


If you need explanation Read this topic

If you need Answer Take test on this topic

Enumeration and Autoboxing
What will be the output of following program?
public class EnumerationBoxing {
    public static void main(String[] arg) {
        Integer input = 1000;
        int input1 = input.byteValue();
        System.out.print(input1 + " ");
        Names names[] = Names.values();
        for (Names name : names) {
            System.out.print(name + " ");
        }
    }
}
enum Names {
    java(4), Merit(2), Campus(3);
    String name = "MeritCampus";
    int length;
    private Names(int length) {
        this.length = length;
    }
}

A. -24 java Merit Campus
B. 1000 java Merit Campus
C. 32 java Merit Campus
D. Compilation error
E. Runtime Error
Topic: Java Enumeration

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 a. byte value of 1000 assignd -24 garbge value bcz of the truncation of the value stored in input,unboxed
for loop prints java merit campus

Posted by Maheshwari Natarajan    2014-06-04 12:30:02


Answer : A
-> we get -24 which is obtained when we convret the Integer to int and the for loop prints the contents of enum i.e., Java Merit Campus

Posted by Deepak Kumar Yadav    2014-06-04 17:27:55


Congratulations Maheshwari Natarajan. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-06-05 04:09:57


© meritcampus 2019

All Rights Reserved.

Open In App