call to super() must be the first statement in constructor body

痞子三分冷 提交于 2019-12-01 04:11:15

Java enforces that the call to super (explicit or not) must be the first statement in the constructor. This is to prevent the subclass part of the object being initialized prior to the superclass part of the object being initialized.

In your case, you don't do anything but local "trivial computation", so all things considered, it would be okay. However, Java's compiler doesn't go to the level of determining whether statements before a call to super actually do any initialization. It just disallows all statements before super().

This statement is true.super() must always be the first statement executed inside a subclass constructor. . for details see Java the complete reference by Herbert Schildt...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!