When do superclasses not have a default constructor?

前端 未结 3 1058
别那么骄傲
别那么骄傲 2021-01-19 16:32

According to the Java tutorial on constructors:

You don\'t have to provide any constructors for your class, but you must be careful when doing this.

3条回答
  •  北荒
    北荒 (楼主)
    2021-01-19 17:13

    So when will the superclass not have a no-argument constructor?

    If you add any other constructor of superclass but forget to add no-arg constructor the compiler will complain. In this case the default constructor of superclass is not provided.

提交回复
热议问题