我可以在java中的公共类中调用参数化构造函数中的默认构造函数吗?

我可以在java中的公共类中调用参数化构造函数中的默认构造函数吗?

问题描述:

我想从公共java类中的参数化构造函数中调用默认构造函数。

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

我能实现吗?

使用 this(); 在参数化构造函数的第一行,它将调用默认构造函数。确保你有默认的构造函数,因为如果你声明一个参数化的构造函数,编译器就不会提供一个构造函数。

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.