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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T03:19:22+00:00 2026-05-21T03:19:22+00:00

I would like to declare a data member of a superclass, private: public abstract

  • 0

I would like to declare a data member of a superclass, private:

public abstract class superclass {
  private int verySensitive;

  abstract int setVerySensitive(int val); // must be overriden by subclass to work properly
}


public class subclass extends superclass {

  @Override
  protected int setVerySensitive(int val) {
    if (val > threshLow && val < threshHigh) // threshHigh is calculated in superclass constructor
       verySensitive = val;
  }
}

As you can see, I have a problem here: superclass can’t access verySensitive because it’s private, but I don’t want to make verySensitive protected because it’s… sensitive.

Also note that setVerySensitive was made abstract because checking against valid values can only be done after superclass has been constructed.

Can you recommend an elegant way of getting out of this “catch 22” situation?

  • 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-05-21T03:19:23+00:00Added an answer on May 21, 2026 at 3:19 am

    I suggest something like this:

    public abstract class superclass {
      private int verySensitive;
    
      final int setVerySensitive(int val) {
        if (checkVerySensitive(val)) {
          verySensitive = val;
        }
      }
      protected abstract boolean checkVerySensitive(int val);
    }
    
    
    public class subclass extends superclass {
    
      @Override
      protected boolean checkVerySensitive(int val) {
        return val > threshLow && val < threshHigh; // threshHigh is calculated in superclass constructor
      }
    }
    

    This is similar to EboMike’s suggestion, but it leaves setVerySensitive(int) with package access instead of making it private.

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

Sidebar

Related Questions

Would like to declare data (Coord a) => Triangle a = Triangle{t0 :: a,
I would like to declare some integer constants in PowerShell. Is there any good
i would like to do this: DECLARE @TmpTable TABLE = select * from someTable
I would like to know how do I declare a record, that has some
I would declare an empty String variable like this: string myString = string.Empty; Is
I have a back up copy of data that I would like to protect
I have a Data access library which I would like to return different data
I would like to define a nullary static template member function which would be
I have an SSRS data source that I would like to test out in
I have a function like this: private void GetRSS(int start, int end) { for

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.