Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Enum questions

  1. #1

    Default Enum questions

    The following code
    enum Days {Sunday, Monday, Tuesday);
     
    Days workday= day.monday;
    simple question members, though not for me. What is being stored in the variable workday? Is the value of Monday which is 1 being stored or the string "monday."


  2. #2
    Senior Member
    Join Date
    Jul 2013
    Location
    Europe
    Posts
    666
    Thanks
    0
    Thanked 121 Times in 105 Posts

    Default Re: Enum questions

    Compile your program, run it and find out.
    If it does not compile or you do not get it to work the way you want it then ask for help here.

  3. #3

    Default Re: Enum questions

    Lol, I already tried figuring out or else I wouldn't have posted it here, frankly speaking. My guess is that "Monday" is being stored in that variable instead of 1. I'm highly positive of this but is the string Monday stored in it?

  4. #4
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,676
    Thanks
    25
    Thanked 329 Times in 305 Posts

    Default Re: Enum questions

    Java is case-sensitive. The compiler also doesn't understand "plurals", so you would still say Days instead of Day (yes, Monday is a singular day, but the enum name is Days, not Day).
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  5. #5
    Senior Member
    Join Date
    Jul 2013
    Location
    Europe
    Posts
    666
    Thanks
    0
    Thanked 121 Times in 105 Posts

    Default Re: Enum questions

    Quote Originally Posted by fahman_khan75@yahoo.com View Post
    Lol, I already tried figuring out or else I wouldn't have posted it here, frankly speaking. My guess is that "Monday" is being stored in that variable instead of 1. I'm highly positive of this but is the string Monday stored in it?
    If you tried you would know, after all, you can simply get the class of every object you create and print its name to the console:
    System.out.println(myVariable.getClass().getSimpleName());
    And if a String is stored then the result will be "String" and if not you will see what it is.

Similar Threads

  1. Enum Values Each Having Their Own Enum Values
    By corosus in forum Object Oriented Programming
    Replies: 1
    Last Post: July 5th, 2013, 07:04 AM
  2. enum
    By anis.laghaei in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 23rd, 2012, 03:19 PM
  3. List of my Java3D Questions, and Proguard questions
    By Zachary1234 in forum Java SE APIs
    Replies: 0
    Last Post: November 16th, 2012, 09:40 PM
  4. [SOLVED] Alternative to Enum
    By Doctor X in forum Java Theory & Questions
    Replies: 2
    Last Post: October 6th, 2012, 03:49 PM
  5. [SOLVED] Enum types, how does he know %s value?
    By beer-in-box in forum Java Theory & Questions
    Replies: 11
    Last Post: September 17th, 2011, 12:47 PM