Results 1 to 6 of 6

Thread: Enum Class

  1. #1
    Robben is offline Member
    Join Date
    Feb 2015
    Posts
    67
    Rep Power
    0

    Default Enum Class

    Suppose I have an enum class named Faction and one of the constants is named DAUNT. I created a class of the enum DAUNT but how can I pass in a DAUNT faction type in for Daunt?

    Java Code:
    public enum Faction {
       ALMIGHTY, AMBITION, DAUNT, RESTLESS, CAN;
    }
    
    //new file
    public class Daunt {
        public Daunt() {
        }
    }

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Enum Class

    how can I pass in a DAUNT faction type in for Daunt
    What does "pass in" mean? Do you mean as an arg to a constructor?
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    Robben is offline Member
    Join Date
    Feb 2015
    Posts
    67
    Rep Power
    0

    Default Re: Enum Class

    Quote Originally Posted by Norm View Post
    What does "pass in" mean? Do you mean as an arg to a constructor?
    Yup.

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Enum Class

    What have you tried? Your other thread on enums has code that takes an array. Remove the [] to make it a plain variable.
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    Robben is offline Member
    Join Date
    Feb 2015
    Posts
    67
    Rep Power
    0

    Default Re: Enum Class

    Quote Originally Posted by Norm View Post
    What have you tried? Your other thread on enums has code that takes an array. Remove the [] to make it a plain variable.
    Actually I figured it out. It will be:

    Java Code:
    Class Daunt {
        Faction myenum = Faction.DAUNT;
        ...
    }
    Thanks!

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: Enum Class

    What are you trying to model here?
    I'm just asking because my alarm bells are going off that there's something not quite right...
    Why tag a class with what the class is when the class name clearly shows that?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Class Interface or enum expected
    By ankiit in forum New To Java
    Replies: 9
    Last Post: 12-22-2011, 09:10 AM
  2. public static enum vs enum class
    By Dipke in forum New To Java
    Replies: 3
    Last Post: 08-30-2011, 10:45 AM
  3. how to use this enum class
    By thorbcn in forum New To Java
    Replies: 1
    Last Post: 07-04-2011, 02:29 AM
  4. Class enum expected
    By Tyre in forum New To Java
    Replies: 10
    Last Post: 04-16-2011, 07:25 PM
  5. class, interface or enum expected?
    By Addez in forum New To Java
    Replies: 2
    Last Post: 08-26-2009, 07:54 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •