Question about constructors in Java

前端 未结 8 641
我寻月下人不归
我寻月下人不归 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:30

    1. Constructor can be created as a private in any case.
    2. Constructor is a special type of method which can be automatically called when we are creating object for the corresponding class.
    3. Constructor does not contain any return values. It just create new objects. Should not provide any return type for constructor.
    4. The default access specifier of the constructor is public

提交回复
热议问题