Overriding Constructors

前端 未结 5 785
庸人自扰
庸人自扰 2021-01-12 16:12

I am greatly confused with Overriding Constructors. Constructor can not be overridden is the result what i get when i searched it in google my question is

p         


        
5条回答
  •  情书的邮戳
    2021-01-12 16:24

    it is not overriding super class constructor and constructor can not be overridden it can be overloaded.

    When you create child class object super class will be instantiated first then sub class will be instantiated. Its like Child can not be existed without parent.

    Compiler will automatically call super class constructor from sub class constructor .

    Sub() {
        super();
        System.out.println("In Sub constructor");
    }
    

提交回复
热议问题