Menu
Topics Index
...
`

Creating Enum


If you need explanation Read this topic

If you need Answer Take test on this topic

Creating Enum
What is the output of the following program?
public class Enum {
    enum Type {
        CAT("Cat"), DOG("Dog"), LION("Lion");
        String st;
        public Type(String st) {
            this.st = st;
        }
    }
    public static void main(String r[]) {
        for (Type type : Type.values()) {
            System.out.print(type.st + " ");
        }
    }
}

A. Cat Dog Lion
B. CAT DOG LION
C. Compilation Error
D. 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.

a

Posted by Sreenath Vallapaneni    2013-08-28 04:03:13


decause it prints the values of the enum elements

Posted by Sreenath Vallapaneni    2013-08-28 04:03:19


enum constructors cannot be public so it gives compiler error..answer is c

Posted by Shashanka Mogaliraju    2013-08-28 04:07:54


Ans. C,coz modifier public not allowed in 'public Type(string st)

Posted by VJ Yaswanth    2013-08-28 04:41:55


Congratulations Vijay Yaswanth. 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-29 03:24:01


© meritcampus 2019

All Rights Reserved.

Open In App