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

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

    1) Is this just homework question, or do you try to reach something? Can you show what you try to reach with an overriding constructor?

    Since the parent constructor is called first, you may modify the base class to your needs in your constructor. Of course, just as far as the access to base attributes isn't private. If you extend a class but don't like their might-be-private attributes, deriving from it was an error.

    2) Can a constructor be private?

    Yes, but do you know what it is good for?

提交回复
热议问题