在java中从另一个调用一个构造函数 [英] call one constructor from another in java
本文介绍了在java中从另一个调用一个构造函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是采访中提出的问题。
如果一个类在java中有多个构造函数,那么我们可以从另一个构造函数调用另一个构造函数?我如何调用我的语法?
This was the question asked in interview. Can we call one constructor from another if a class has multiple constructors in java and when?How can I call I mean syntax?
推荐答案
你可以,我知道的语法是
You can, and the syntax I know is
this(< argument list >);
您也可以通过
super(< argument list >);
这两个调用只能作为构造函数中的第一个语句其他构造函数,之前的任何操作)。
Both such calls can only be done as the first statement in the constructor (so you can only call one other constructor, and before anything else is done).
这篇关于在java中从另一个调用一个构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文