I'm having trouble initializing a basic enum of days of the week. Here is my code:

+2 votes
asked Oct 30, 2015 in Others by user10
public class Ch3_12 
{   
    public static void main(String[] args) 
    {
        public enum Day {MON, TUE, WED, THU, FRI, SAT, SUN}

    }
}

1 Answer

0 votes
answered Oct 30, 2015 by user234 (980 points)
 
Best answer

Read the error messages the compiler gives you:

public static void main(String[] args)
{
    public enum Day {MON, TUE, WED, THU, FRI, SAT, SUN}
    ^^^^^^ Modifier "public" not allowed here
}

... so you remove the modifier:

public static void main(String[] args)
{
    enum Day {MON, TUE, WED, THU, FRI, SAT, SUN}
    ^^^^^^^^ enum must not be local
}

... so you move it out of the method scope:

enum Day {MON, TUE, WED, THU, FRI, SAT, SUN}

public static void main(String[] args)
{
    // no more compiler errors...
}

If you don't understand an error message, you can google it and find explanations easily.

Welcome to I Can Crack, where you can ask questions and receive answers from other members of the community.

68 questions

47 answers

3 comments

5,318 users

...