0

Example

public enum STUFF
{
    THING("Ok"), STUFF("Sweet"), PEOPLE("umm"), CAR("Vrrm");

    String contents;

    STUFF(String x)
    {
       contents = x;
    }

    public String getContents()
    {
        return ??
    }

}

Desired result:

System.out.print(STUFF.CAR.getContents());
//Vrrm
1
  • ahh... I guess it really was that simple @PrinceJohnWesley Commented Nov 29, 2012 at 17:06

2 Answers 2

4

You should review the planets example at: http://docs.oracle.com/javase/tutorial/java/javaOO/enum.html

public enum STUFF
{
    THING("Ok"), STUFF("Sweet"), PEOPLE("umm"), CAR("Vrrm");

    private final String contents;

    STUFF(String x)
    {
        contents = x;
    }

    public String getContents()
    {
        return contents;
    }
 }
Sign up to request clarification or add additional context in comments.

1 Comment

The only dumb thing you could have done was to have not asked your question. No shame in learning!
3

The assignment in the constructor is wrong.

x = contents;

should be: -

contents = x;

And the return value in getContents() should be: -

public String getContents()
{
    return contents;
}

1 Comment

@stackoverflow.. It's ok. I thought that was intentional. But that should get you what you want. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.