问题 单项选择题

阅读下面程序 class Test implements Runnable {  public static void main(String[] args) {   Test t=new Test();   t.start():  }  public void run() {} } 下列关于上述程序的叙述正确的是

A.程序不能通过编译,因为start()方法在Test类中没有定义

B.程序编译通过,但运行时出错,提示start()方法没有定义

C.程序不能通过编译,因为run()方法没有定义方法体

D.程序编译通过,且运行正常

答案

参考答案:A

解析: 创建线程有两种方法:实现java.lang.Runnable接口;继承Thread类并重写run()方法。start()是Thread类中的方法,而本程序中的Test类实现了Runnable接口,Runnable接口中只定义了一个抽象方法run(),故Test类不能调用start()方法。编译时会出现start()方法未定义的错误。

选择题
单项选择题