How to inherit some parameters of superclass constructor to subclass constructor? For example I want only weight and height to be inherited to subclass, how to construct the constractor for subclass?
public abstract class People {
protected double weight;
protected int height;
protected String mood;
public People(double weight, int height, String mood) {
this.weight = weight;
this.mood = mood;
}
public class Health extends People {
private String bloodType;
public Health(double weight, int height, String bloodType){
super(weight,height); // this won't work
this.bloodType = bloodType;
}
Either you need to supply a mood to the constructor in the superclass (possibly as a constant), or you need to add a constructor to the superclass which doesn't take a mood. You need to ask yourself whether every Question/People
really needs a mood, and what the mood of a DivisionQuestion/Health
is. (It doesn't help that your code is currently inconsistent in terms of the classnames it's using.)
Just like calling a normal method, you can't provide arguments for some parameters but not others.
See more on this question at Stackoverflow