Question about constructors in Java

前端 未结 8 647
我寻月下人不归
我寻月下人不归 2021-01-20 14:52

I have few questions regarding Java constructors

  1. Can a constructor be private? If yes then in which condition?
  2. Is a constructor a method or not?
8条回答
  •  佛祖请我去吃肉
    2021-01-20 15:29

    1. Yes.
    2. Yes.
    3. because a constructor is called by new. What returns the object is the new, the constructor simply sets up the internal state.
    4. Public.

提交回复
热议问题