求救 下面的 this()是什么意思啊 ?class TT{
public TT(String s){
this();
System.out.println(s);
}
}
public class Test extends TT{
public static void main(String args[]){
Test t = new Test("This");
}
public Test(String s){
super(s);
}
}
public TT(String s){
this();
System.out.println(s);
}
}
public class Test extends TT{
public static void main(String args[]){
Test t = new Test("This");
}
public Test(String s){
super(s);
}
}
第一,我还是不是很懂;
第二,这样运行会提示this()这里有错啊
class TT {
public TT() {
System.out.println("hi, i am TT()!");
}
public TT(String s) {
this();
System.out.println(s);
}
}
要不你给我说说super,其实我也不是太懂,我就知道是调用父类的构造方法
2.如果一个类同时提供无参数构造函数和带参数构造函数,需明确定义才行。
3.this()调用本类的无参数构造函数,生成一个本类实例。
上述代码应改为:
class TT
{
//无参数构造函数
public TT(){}
//带参数构造函数
public TT(String s)
{
this();
}
}