下面程序段的输出结果是( )。 class Test{ public static void mai n(Stri ng args[]){ MyThread t =ne w MyThread(); t .displayOutput("t has been

admin2012-12-02  40

问题 下面程序段的输出结果是(  )。
class Test{
public static void mai n(Stri ng args[]){
MyThread t =ne w MyThread();
t .displayOutput("t has been createD");
t .start();


Class MyThread extends Thread{
public void displayOutput(Stri ng s){
Syste m.out .pri ntln(s);

public void run(){
displayOutput("t is runni ng .");



选项 A、t has been created .
B、t has been created .Tis runni ng .
C、t is runni ng .
D、编译出错

答案B

解析 start()方法就可以启动该线程,线程也就处于可运行状态Runnable。Start()方法产生了线程运行需要的系统资源,并调用线程体,也就是run()方法,使得线程可以进入运行状态。程序运行时首先创建一个新的线程对象t ,并调用displayOutput(Stri ngs)方法输出t has beencreated。t .start()方法调用run()方法,输出t is runni ng ,所以正确答案为选项B。
转载请注明原文地址:https://kaotiyun.com/show/GBID777K
0

相关试题推荐
最新回复(0)