Can I call default constructor from parameterized constructor inside public class in java?

后端 未结 6 1330
暗喜
暗喜 2021-02-19 22:44

I want to call default constructor from a parameterized constructor inside a public java class.

Can I achieve it?

6条回答
  •  爱一瞬间的悲伤
    2021-02-19 22:50

    Use this(); in the first line of the parametrized constructor and it will call your default constructor. Make sure you have default constructor as compiler will not provide one if you declare a parametrized constructor.

提交回复
热议问题