1

So i have an abstract class:

public abstract class Superclass {
    private final boolean isTrue;
    private final int number1;
    private final int number2;
    private final int number3;

    public Superclass(boolean isTrue, int number1, int number2, int number3) {
        this.isTrue = isTrue;
        this.number1 = Math.abs(number1);
        this.number2 = Math.abs(number2);
        this.number3 = Math.abs(number3);
    }

On top of that i created a subclass of "Superclass" which is supposed to have 2 public constructors:

public class Subclass extends Superclass{

    public Subclass(int number2, int number3) {
     ...
    }

    public Subclass(int number1, int number2, int number3) {
     ...
    }

Now i dont know what i should write inside of those contructors to make them work, because i think have to call super(isTrue, number1, number2, number3) and thats obviously not possible. I dont want to add any additional attributes to the subclass. Is there any way to make that work? Thanks already in advance :)

vader69
  • 27
  • 3
  • 2
    You have to provide values for the parameters required by the superclass that are not provided to the subclass constructor, e.g. `super(true, 0, number2, number3)`. – Robby Cornelissen Dec 06 '19 at 02:57

1 Answers1

1

You have to provide (default) values for the parameters required by the superclass that are not provided to the subclass constructor.

For example:

public Subclass(int number2, int number3) {
    super(true, 0, number2, number3);
}
Robby Cornelissen
  • 91,784
  • 22
  • 134
  • 156