我可以在java中的公共类中调用参数化构造函数中的默认构造函数吗? [英] Can I call default constructor from parameterized constructor inside public class in 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.
这篇关于我可以在java中的公共类中调用参数化构造函数中的默认构造函数吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文