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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:23:28+00:00 2026-06-01T04:23:28+00:00

Basically, I have: public abstract class AbstractClass { public AbstractClass( Type arg0, Type arg1,

  • 0

Basically, I have:

public abstract class AbstractClass {
    public AbstractClass( Type arg0, Type arg1, Type arg2 ) {
        // do some stuff with all those args
    }

    public AbstractClass( Type onlyOneArg ) {
        // do different stuffs with this different arg.
    }

    protected someMethods() { /* ... */ }
}

And I have a few problems in the subclasses:

  • First, I have to -in most of the cases- uselessly rewrite the constructors. Not very annoying, just a bit dirty to the eye.
  • And, more important, I am not forced to implement both constructors (although both are used in the program).

Example of my current subclasses:

public class MyClass extends AbstractClass {
    public MyClass( Type arg0, Type arg1, Type arg2 ) {
        super( arg0, arg1, arg2 );
    }

    public MyClass( Type onlyOneArg ) {
        super( onlyOneArg );
    }
}

And

  • I have to be able to write some particular code in a subclass’s constructor if I want.
  • I have too many shared code that I want to keep in the abstract class.

Can I do something about that ?
Are there something I don’t know about Java ? Or is my design bad ? Or.. ?

  • 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-01T04:23:29+00:00Added an answer on June 1, 2026 at 4:23 am

    The subclass has to call either one (or both, if you redefine both as in your example) of the superclass constructors; but you cannot force it to redefine constructors with the same signatures of the superclass.

    The only way to guarantee that a superclass constructor is called is to have only one constructor in the superclass.

    I think you should think of a way to redesign your superclass (maybe creating 2 classes) to have only one constructor if you want it to always be called.

    But, if want a specific constructor to be present in a subclass, you should isolate the “construction” concern in a factory; where you can have special factory classes for each of your subclasses. Your factories would implement this interface:

    interface AbstractClassFactory {
      AbstractClass create( Type arg0, Type arg1, Type arg2 );
      AbstractClass create( Type onlyOneArg );
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have abstract BaseController, which basically looks like below: public abstract class BaseController :
I have the following code public abstract class Event { public void fire(Object... args)
Basically I have a simple base class: public abstract class BasePoco { public virtual
I have a class which is basically a copy of another class. public class
Basically, I have the following so far: class Foo { public override bool Equals(object
I have an abstract class BaseItem declared like this: public abstract class BaseItem {
I have one class called Person that basically looks like: public class Person {
I have an issue with some inheritance I'm doing. Basically, I have an abstract
I have a follwing class structure: public abstract class AbstractFoo { public virtual void
Basically I need to have an abstract class, that contains a field of a

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.