Search code examples
javainheritancesubclasssuper

How can I solve the problem using super keyword in Java


public class CommissionCompensationModel
{
  private double grossSales;
  private double commissionRate;

  public CommissionCompensationModel(double grossSales, double commissionRate)
  {
    this.grossSales=grossSales;
    this.commissionRate=commissionRate;
  }
}

This is my CommissionCompensationModel class

public class BasePlusCommissionCompensationModel extends CommissionCompensationModel
{
  protected double baseSalary;

  public void BasePlusCommssionCompenationModel(double grossSales, double commissionRate, double bs)
  {
    **super(grossSales, commissionRate);**
    this.baseSalary=bs;
  }
}

This is a subclass of the previous one. It intends to inherit its superclass and add the base salary property. However, the IDE tells me there's some problem with strong text. How to solve the problem?


Solution

  • Constructors don't have a return type, not even void. Additionally, you have a typo there - BasePlusCommssionCompenationModel instead of BasePlusCommissionCompensationModel (missing an "i" afer the "m"s).

    Fix the typo and remove the return type and you should be fine:

    public BasePlusCommissionCompensationModel(double grossSales, double commissionRate, double bs)
    {
        super(grossSales, commissionRate);
        this.baseSalary=bs;
    }