问题 填空题

请写出下面程序的运行结果:
public class Test extends TT
public static void main(String args[])
Test t=new Test("Tom.");

public Test(String s)
super(s);
System.out.print("How are you");

public Test()
this("I am Jack.");


class TT
public TT()
System.out.print("Hi!");

public TT(String s)
this();
System.out.print("I am"+s);


结果: 【15】

答案

参考答案:Hi ! I am Tom.How are you

解析: 本题考查类的继承。从main()方法作为程序入口,首先执行Test t=new Test(“Tom.”)语句,此时将调用 Test(String s)构造方法,而进入此方法后由 super(s)语句来调用TT.TT(String s),而执行 this()语句将会调用TT.TT(),因此,首先由 System.out.print("Hi!")语句执行输出。接下来才是System.out.print("I am"+s)语句,然后才是 System.out.print("How are you"),最后程序结束。要注意区分this和super所对应的类。

判断题
单项选择题