Menu
Topics Index
...
`

Sun Moon Stars


If you need explanation Read this topic

If you need Answer Take test on this topic

Sun Moon Stars
What will be the output of the following program?
public class SunMoonStars {
    public static void main(String[] args) {
        String bodies[] = {"Sun", "Moon", "Earth", "Pluto"};
        for (String body : bodies) {
            print(Planets.valueOf(body));
        }
    }
    private static void print(ValueProvider v) {
        if (v instanceof Planets) {
            System.out.print("#" + v.getValue());
        } else {
            System.out.print("@@@@");
        }
    }
}
interface ValueProvider {
    String getValue();
}
enum Planets implements ValueProvider {
    Sun, Earth, Mars, Venus;
    public String getValue() { return toString(); }
}

A. #Sun#Earth
B. #Sun@@@@#Earth@@@@
C. Compilation Error because enum can not implement interfaces
D. Compilation Error for some other reason
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.

A

Posted by Naveen Bala Madhanu    2014-06-23 13:25:18


Ans is E..IllegalArgmntExcptio enum doesnt contain Moon n pluto

Posted by Uday Kumar    2014-06-23 13:32:00


Answer : E enum doesnot define the constants Moon and Pluto

Posted by Deepak Kumar Yadav    2014-06-23 13:34:36


e

Posted by Bharat Tipre    2014-06-23 15:07:45


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

Posted by Merit Campus    2014-06-24 04:02:46


© meritcampus 2019

All Rights Reserved.

Open In App