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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:13:20+00:00 2026-05-20T05:13:20+00:00

Before you start reading I would like to clarify: I have already thought of

  • 0

Before you start reading I would like to clarify:

I have already thought of other designs and work arounds
I’m only interested in the problem I exposed and not “changing” it (so no solutions such as delete the points in A and create new points fields in B and C…


lets consider the following code:

public class A {
    protected cpVect[][] points = null;
    ...
}

and its classes that inherits it:

    public class B extends A{

            ...
    }

    public class C extends A{

            ...
    }

so far so good.

my problem is that for B and C contains arrays of points that will be created in the constructor using something like

if(points == null){calculate points code}

the problem is as follow

points in A can’t be static because the dimensions are different in B and C.

but every instance of B will share the B points and every instance of C will share the C points. (in other words a Square will always be a square and a triangle will always be a triangle). and therefore I want to have the B:points and C:points static so that i don’t get duplicates of the values for every instance.

So is there a way to redefine points as static in B and C when it is not static in A?

  • 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-20T05:13:21+00:00Added an answer on May 20, 2026 at 5:13 am

    If you access points solely through property methods (getters/setters) you can do whatever you want in the subclasses. If you use inheritance, A will have to be an abstract class. Otherwise you’d always carry around the empty points variable in A (losing 8 bytes, probably).

    In this case the hierarchy would look like this:

    abstract class A {
        abstract public cpVect[][] getPoints();
    
        // more methods ...
    }
    
    public class B extends A {
    
        private final static cpVect[][] POINTS = calculatePoints();
    
        @Override
        public cpVect[][] getPoints() {
            return POINTS;
        }
    
        private cpVect[][] calculatePoints() {
            // ...
        }
    }
    

    And the same for C. If A includes no other state or functionality, you should make it an interface.

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

Sidebar

Related Questions

I would like two threads work like this: First thread will append values to
I have files with the words written on different speaking languages. I would like
Before I start, I'm already aware that object immutability in Python is often a
I have asked a similar question before here , but after much thought, and
I would like to start a Summer Project just for the sake of improving
Before you start reading... You should know that there are many questions below... I
Before start let me tell my experience: I am experienced with C#.NET, web services,
I want to get one record before start date and end date DtpFrom means
Am using Mediainfo library in my C# project,before start invoking this dll,i just ran
I usually try to do TDD with not much analysis (no diagrams) before start

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.