Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8082105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:58:38+00:00 2026-06-05T16:58:38+00:00

I understand I can create an enum like this: public enum MyEnum { ONE(1),

  • 0

I understand I can create an enum like this:

public enum MyEnum {
   ONE(1),
   TWO(2);
   private int value;
   private MyEnum(int value) {
      this.value = value);
   }
   public int getValue() {
      return value;
   }
}

But I have some questions:

1) It seems that the enum values are declared at the start. Is there a particular format for this. Could I declare them anywhere?

2) Is is possible to declare an enum with more than one constructor and is this something that people sometimes do?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T16:58:39+00:00Added an answer on June 5, 2026 at 4:58 pm
    public enum MyEnum {
       ONE(1),
       TWO(1, 2);
       private int value1, value2;
    
       private MyEnum(int value) {
          this.value1 = value;
          this.value2 = 0; // default
          // this.value2 = getFromSomewhereElse(); // get it at runtime
       }
    
       private MyEnum(int value1, int value2) {
          this.value1 = value1;
          this.value2 = value2;
       }
    
       public int getValue1() {
          return this.value1;
       }
    
       public int getValue2() {
          return this.value2;
       }
    }
    
    1. Yes, you must declare the enum values at the start. Always.
    2. See code above. It is possible. If people do it depends on the application. If you have a lot of fields and most of them should be a default value, it is a good thing to use multiple constructors. Also, the values for the fields could be read at runtime (from a file or another static class).
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is how I understand I can implement the singleton pattern in C#: public
For reasons that only the developers can understand, Firefox will create and open .url
I understand how exports works, but how can I create a variable in my
I understand that I can call ToString().IndexOf(...), but I don't want to create an
I can understand the difference between a signed char and an unsigned one. But
I understand I can apply several options to the ServiceContract (like Name , Namespace
As best as I can understand, iBooks are much just like interactive PDFs. What
i came across this http://www.brighthub.com/mobile/google-android/articles/48845.aspx i understand i can create a view. But i
I can't understand how can I solve this exercise. I need to make a
How can I treat a Nullable just like I do with Enum within the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.