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

  • Home
  • SEARCH
  • 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 9152219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:59:20+00:00 2026-06-17T11:59:20+00:00

Currently I declare all my static fields like so: public static final int EXAMPLE_OF_STATIC_FIELD

  • 0

Currently I declare all my static fields like so:

public static final int EXAMPLE_OF_STATIC_FIELD = 0;

Say I have a base class with fields that represent all errors that could ocurre inside the class:

public class Base {

    public static final int ERROR_1 = 0;
    public static final int ERROR_2 = 1;
    public static final int ERROR_3 = 2;

}

If I extend this base class and I would like to add more Error types to the class, I would do the following:

public class OffSpring extends Base {

        public static final int NEW_ERROR_1 = 3;

    }

For me to declare new Error types, I need to know the value of the Error types from the base class, which (in my opinion) in not very convenient, since I could accidentally declare an Error Type in an offspring class of the Base class with the same value as an Error type from the Base class. For example:

public static final int NEW_ERROR_1 = 0;

which would be the same as

public static final int ERROR_1 = 0;

which would conflict…

I thought of maybe using an Enum Class, however it turns out that you can’t extend it.
Can enums be subclassed to add new elements?

Another option would be to use String value type instead of int value type for all the static fields, but this is not a very efficient solution…

How can I add more fields to an offspring of a class, without them conflicting with the super class?

  • 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-17T11:59:21+00:00Added an answer on June 17, 2026 at 11:59 am

    I would question whether you really want to do this. If the constants are private to their declaring classes, why does it matter if they reuse the same values? If there is a context where it is important that different errors do not use the same values, then that suggests strongly that they should not actually be private.

    If you do actually want to do this, you could do something like this:

    public class Base {
        private static final int ERROR_1 = 0;
        private static final int ERROR_2 = 1;
        private static final int ERROR_3 = 2;
        protected static final int LAST_ERROR = ERROR_3;
    }
    
    public class OffSpring extends Base {
        private static final int NEW_ERROR_1 = Base.LAST_ERROR + 1;
    }
    

    If you want to have multiple subclasses of Base which each define their own error codes, though, you’re in trouble.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a base class that declares a private non-static reference to the DataBase
I currently have a page which is declared as follows: public partial class MyPage
I have a class, Plotter , which has a static event (declared public static
I'm currently using reflection to get the declared Fields of a GUI class. However
I know that all members of a POCO class for NHibernate must be defined
I have read in Chapter 4 of the NHibernate docs that all of a
Currently I have this code for my underlying model: Public Enum vehicleType Car Lorry
In class's derived from a Component I sometimes see events declared like: private static
I need a way to have a single static variable for all kinds of
I'm currently looking at creating an abstract class Building . I would then like

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.