Menu
Topics Index
...
`

Creating Enum class


If you need explanation Read this topic

If you need Answer Take test on this topic

Creating Enum class
What will be the output of the following program?
enum MCampus {
    Merit(6), Campus(5), MeritCampus(11);
    MCampus(int result) {
        this.result = result;
    }
    private int result;
    public int getResult() {
        return result;
    }
}
public class MC {
    MCampus size;
    public static void main(String[] args) {
        MC m = new MC();
        m.size = MCampus.Merit;
        MC c = new MC();
        c.size = MCampus.MeritCampus;
        for (MCampus mc : MCampus.values())
            System.out.print(mc + "," + mc.getResult() + "-");
    }
}

A. Merit,5-Campus,6-MeritCampus,11-
B. Merit,6-Campus,5-MeritCampus,11-
C. Merit,0-Campus,0-MeritCampus,0-
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.

ans b.
enum s usd.
for loop prints givn ordr of enum clas.

Posted by Maheshwari Natarajan    2014-07-10 12:53:16


Ans is b..using for loop we are print Constrctrs in Enum and values in those enums by calling getResult()

Posted by Uday Kumar    2014-07-10 13:06:30


Answer B
enum keywrd used so the objct insid the enum automaticaly asign values increasing ordr.
for loop prints according to the ordr of enum.
value() method returns enumeration constants

Posted by NagaRaj Nataraj    2014-07-10 13:09:13


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-07-11 04:18:32


B

Posted by Arul Mani Dubey    2014-07-11 11:21:09


© meritcampus 2019

All Rights Reserved.

Open In App