我有构造函数树(int a,int b,int c)和第二个构造函数树(int a,int b,int c,String s)。如何从第一个构造函数加载第二个构造函数以节省编写所有逻辑?
我想过这样的事情,但它给了我“空”对象。
public Tree(int a, int b, int c){
Tree t1 = new Tree(a, b, c, "randomString");
}
神奇的词是this
, e.g.
public Tree( int a, int b, int c, String d ) {
// Do something
}
public Tree( int a, int b, int c ) {
this( a, b, c, "randomString" );
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)