Java: Snack from Constructor

来源:互联网 发布:php开发扫码支付 编辑:程序博客网 时间:2024/05/21 06:22

Description:

Good in this example isan abstract base class, which has a non-defaultconstructor that calls for a name.

Food is a derived class ofGood. There are two constructors inFood, one is that fromGood, the other is designed to take one moreparameter called price.

As the base class Good has a constructor thattakes a specified parameter, so any constructor in any classinheriting it must also takes the same parameter. Having met thisconstraint, the constructors in a derived class can take some moreparameters, but in the body of the constructors, the one from thebase class must be called directly or indirectly, as the error inthe second picture shows.

 

Java: <wbr>Snack <wbr>from <wbr>Constructor

 

Java: <wbr>Snack <wbr>from <wbr>Constructor


0 0
原创粉丝点击