Is Constructor Overriding Possible?

后端 未结 14 1931
时光说笑
时光说笑 2020-12-08 00:31

What i know is, the compiler writes a default no argument constructor in the byte code. But if we write it ourselves, that constructor is called automatically. Is this pheno

14条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-08 01:19

    Cannot override constructor. Constructor can be regarded as static, subclass cannot override its super constructor.

    Of course, you could call protected-method in super class constructor, then overide it in subclass to change super class constructor. However, many persons suggest not to use the trick, in order to protect super class constructor behavior. For instance, FindBugs will warn you that a constructor calls a non-final method.

提交回复
热议问题