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 8462621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:12:59+00:00 2026-06-10T14:12:59+00:00

I have this class declaration abstract class A { protected static String message =

  • 0

I have this class declaration

abstract class  A {
    protected static String message = "Hello";
}

And I want this field to get propagated to subclasses, to avoid typing protected static String message = "Whatever"; (the value of this static field is different in each subclass) in all the subclasses.

I know this won’t work:

class B extends A {

    static {
        message = "Blablabla";
    }
}

Because it will actually modify A‘s message because static fields/methods are not inherited. What I want to know is if there’s any other way of doing this, or if I have to rewrite the static field on each subclass.

  • 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-10T14:13:01+00:00Added an answer on June 10, 2026 at 2:13 pm

    There’s no straightforward way to do it.

    You may consider use some utility class which maps a Class object to a message. This will help you use general methods to work with messages based on this.getClass().

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

Sidebar

Related Questions

I have this class: class OriginalClass { string FirstItem; List<string> ListOfSecondItems; } I want
i have this class public class Image { public string url { get; set;
I have the following abstract class class Language { const std::string name ; protected:
I have a function B that has this declaration: public void B(Class<? extends C>
I have this class: Class B { private String D; private String E; }
I have an abstruct class with abstract method, the method param is generic. this
I have an abstract class. I'm extending that class. I'm getting this error: Fatal
I have this abstract base class ODESolver: //ODESolver.h #ifndef ODESolver_H #define ODESolver_H #include doublependulum.h
I have a method with this signature: protected final Map<String, Object> buildOutputMappings( AbstractDataObject ado,
Let's say I have this base class: abstract public class Base { abstract public

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.