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

后端 未结 11 1850
旧时难觅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:00

    1. No we can't use a constructor out of class because sub class is treat constructor as a method.. without return type.
    2. You can use it as a private but if a constructor of a class is private then you cannot make the obj of the respected class into another class.

提交回复
热议问题