3
public static enum enuGender{ MALE, FEMALE, UNKNOWN } public enuGender gender; //&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& Constructors &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& public Athlete(String firstName, String lastName, int age, enuGender gender) { super(); this.firstName = firstName; this.lastName = lastName; this.age = age; this.gender = gender; } 

I have this code in an "Athlete" class, however when I try to instantiate an athlete in my main class like so:

Athlete ath = new Athlete("Jim", "Denver", 33, enuGender.MALE); 

I am told the enuGender cannot be resolved to a variable. Can I not pass an enum value in the constructor??

1
  • 1
    As an aside, you should capitalize the first letter of the Enum type to follow naming standards. Commented Nov 17, 2015 at 22:40

1 Answer 1

9

Presumably the enuGender enum is nested within the Athlete class. To refer to that enum from outside that class, you must specify the enclosing class name. Try

Athlete ath = new Athlete("Jim", "Denver", 33, Athlete.enuGender.MALE); 

The alternative would be to pull that enum declaration out of the Athlete class so that specifying the enclosing class name would be unnecessary.

Also, enum names follow Java conventions for class names; Gender is a better name.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for editing the naming suggestion in to your answer.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.