class Jerry {
public Jerry() {
System.out.println("Jerry");
}
public void hello() {
System.out.println("Hello in Jerry");
}
}
class Tom extends Jerry {
public Tom() {
System.out.println("Tom");
}
public Tom(String s) {
this();
System.out.println("I am " + s);
}
public void hello() {
System.out.println("Hello in Tom");
}
}
public class Test3 extends Tom {
public Test3() {
this("test");
System.out.println("Test");
}
public Test3(String s) {
super(s);
System.out.println("Hello " + s);
}
public static void main(String args[]) {
Test3 t = new Test3();
t.hello();
}
}
答案
Jerry
Tom
I am test
Hello test
Test
Hello in Tom
this()就是调用自身的无参构造函数。打印的tom就是这个无参构造函数的内容的。
转载:http://blog.sina.com.cn/s/blog_49faf32901008pap.html 作者:Joe Armstrong原文:What’s all this fuss about Erlang译者:朱照远(Joshua Zhu) 许式伟(XuShiWei)What’s all this fuss about Erlang?没人可以预言未来,但我却打算做一些有......
答案就在这里:What’s all this fuss about Erlang
----------------------你好,人类,我是来自CSDN星球的问答机器人小C,以上是依据我对问题的理解给出的答案,如果解决了你的问题,望采纳。
已经调用过了这个this()了