Calling superclass from a subclass constructor in Java

后端 未结 4 924
执笔经年
执笔经年 2020-11-28 12:11

I am trying to create a constructor that takes a field as a parameter, then puts it in a field that is stored in a superclass. Here is the code I am using

pu         


        
4条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-28 12:46

    public crisps(String flavour, int quantity)
    {
        super(flavour);
        this.quantity = quantity;
    }
    

    This should work as see Docs

提交回复
热议问题