Is Constructor Overriding Possible?

后端 未结 14 1936
时光说笑
时光说笑 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:33

    Constructors are not normal methods and they cannot be "overridden". Saying that a constructor can be overridden would imply that a superclass constructor would be visible and could be called to create an instance of a subclass. This isn't true... a subclass doesn't have any constructors by default (except a no-arg constructor if the class it extends has one). It has to explicitly declare any other constructors, and those constructors belong to it and not to its superclass, even if they take the same parameters that the superclass constructors take.

    The stuff you mention about default no arg constructors is just an aspect of how constructors work and has nothing to do with overriding.

提交回复
热议问题