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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:21:47+00:00 2026-05-27T09:21:47+00:00

I have an abstract method call in my super’s constructor. I run into the

  • 0

I have an abstract method call in my super’s constructor. I run into the error “Constructor call must be the first statement in the Constructor.” because I need to initialize some state in my subclasses before calling the super’s constructor.

I understand that the constructor call must be first.. but it’s making me have some problems.

I have an abstract method in my superclass that all subclasses implements theirselves.
But the subclass constructor requires arguments that must be processed before the runs the abstract method.

In my code, I have the abstract method in the SuperClass constructor, so you will understand of course the problem:
Super class does:

  1. Get info1 and info2 using super(i1, i2)
  2. Performs abstract method through the subclass

But little did the Superclass constructor know that it also needed info3 and info4, which are declared on the lines beneath
the super()-line.

I’ve been trying to think of ways for the Superclass constructor to have to go back and gather the information from the subclass before
it executes the method, but I haven’t thought of anything.

Also the method cannot require arguments, as the arguments are different for all the subclasses’s abstract method.

Those of you who are experienced, how do I get around this?

After some Googling, it seems to have to do with this:
http://webcache.googleusercontent.co…s-constructor/

But is still a novice, so find it hard to hang on to ..
I feel I could’ve avoided all of this trouble if I could just use the super() after the subclasses constructors have been processed.

Code on request:

    abstract public class Prylar {
      abstract public Integer value();

      private String itemName;
      private Person owner;


      public Prylar(Person thisOwner, String iN){
      owner = thisOwner;
      itemName = iN;
          value = value();  
}



    public class Smycken extends Prylar{
     private int antalStenar;
     private boolean guldEllerSilver;
     private int value;

     public Smycken (Person who, String n, int aS, boolean material){
     super(who,n);

     antalStenar = aS;
     guldEllerSilver = material;
}




public Integer value() {

    if (guldEllerSilver){
        value = 2000;
    }
    else{
        value= 700;}
    value += (500*antalStenar);

    return value;
}

}

And I just want to end this by saying thank you all for taking your time to read and help a guy out. I really appreciate it. Hopefully when someone else has a similar problem, they will stumble upon this.

Thanks guys!

  • 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-27T09:21:48+00:00Added an answer on May 27, 2026 at 9:21 am

    The problem you are facing is that the subclass instance is not constructed completely when you call the abstract (or any overriden) method from the baseclass. The only way to be sure that the object instance is constructed completely is to have finished its constructor.

    One way to solve your issue is to use the constructors only for construction of the instances and to leave (dynamic) initialisation to a method. In cases like this you can use methods like:

    private boolean initialized = false;
    
    public synchronized boolean init() {
        if (!initialized) {
             // allocate resources, call abstract method(s)
             initialized = true;
        }
        return initialized;
    }
    
    public synchronized void cleanup() {
        if (initialized) {
             // free resources, call abstract method(s)
             initialized = false;
        }
    }
    

    calling code can call the init() and cleanup() methods explicitly or leave the calls to init() to a pattern as in:

    public void doSomething() {
    
        if (init()) {
            // go!
        }
    }
    

    Inside your init method you can call the abstract methods and be sure that the complete object instance is constructed correctly.

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

Sidebar

Related Questions

I have an abstract class with some methods,including an abstract method(Execute()).This method is overridden
I have an abstract class, Foo, that has a non-abstract method called Bar. I
Just I am learning Generics.When i have an Abstract Method pattern like : //Abstract
i have an abstract class BaseClass with a public insert() method: public abstract class
I have an abstract class defining a pure virtual method in c++: class Base
I have an abstract class that has a virtual method. The method is virtual
I have the following class: public abstract class AbstractParent { static String method() {
I have an abstract Java class MyAbstractClass with a private method. There is a
I have defined an abstract method in my base class to take in a
I have created an abstract base class Animal which has public virtual abstract method

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.