Can we override a constructor in Java and can a constructor be private?

后端 未结 11 1851
旧时难觅i
旧时难觅i 2020-12-29 14:21

I would appreciate an explanation for these questions:

  1. Can we Override a constructor in Java?
  2. Can a Constructor be private?<
11条回答
  •  失恋的感觉
    2020-12-29 15:04

    You can use callback:

    In parent class:

    protected void onCreate(){}
    
    SomeClass(){
    //Constructor code
    onCreate()
    }
    

    in child:

    @Override
    protected void onCreate(){
    //Child constructor code
    }
    

提交回复
热议问题