Menu
Topics Index
...
`

Creating Enum classes


If you need explanation Read this topic

If you need Answer Take test on this topic

Creating Enum classes
What will be the output of the following program?
public class EnumerateIt {
    public static void main(String[] args) {
        for (A a : A.values()) {
            System.out.print(a.name() + " " + a.ordinal() + " ");
            try {
                B b = B.valueOf(a.name());
                System.out.print(b.name() + " " + b.ordinal() + " ");
            } catch (Exception e) {
                System.out.print(a.name() + " " + a.ordinal() + " ");
            }
        }
    }
}
enum A {
    A, B, C
}
enum B {
    B, C, D
}

A. A 0 A 0 B 1 B 0 D 2 D 2
B. A 0 A 0 B 1 B 1 C 2 C 2
C. A 0 A 0 B 1 B 0 C 2 C 1
D. Some other output
E. Compilation Error or 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.

c is the answer we are printing the values of A enum for the first 2 interations and the we are going to b enum in try block here are we are tagging the oridinal values as well with the values in the enum

Posted by Karteek Paruchuri    2013-08-26 12:52:40


C is the answer

Posted by Vani Reddy Nareddy    2013-08-26 16:28:11


Congratulations Karteek Paruchuri. You are this dose winner. Please send us your mobile details in a private message and we will process the recharge asap.

Posted by Merit Campus    2013-08-27 03:47:52


got the rc thankyou

Posted by Karteek Paruchuri    2013-09-01 05:15:38


© meritcampus 2019

All Rights Reserved.

Open In App