class MyThread extends Thread {  public void run() { System.out.println(“AAA”); }  public void run(Runnable r) { System.out.println(“BBB”); }  public static void main(String[] args) {  new Thread(new MyThread()).start();  }  }   What is the result?()  A、

题目

class MyThread extends Thread {  public void run() { System.out.println(“AAA”); }  public void run(Runnable r) { System.out.println(“BBB”); }  public static void main(String[] args) {  new Thread(new MyThread()).start();  }  }   What is the result?()  

  • A、 AAA
  • B、 BBB
  • C、 Compilation fails.
  • D、 The code runs with no output.

相似考题
更多“class MyThread extends Thread {  public void run() { System.out.println(“AAA”); }  public void run(Runnable r) { System.out.println(“BBB”); }  public static void main(String[] args) {  new Thread(new MyThread()).start();  }  }   What is the result?()  A、 ”相关问题
  • 第1题:

    通过实现Runnable接口创建线程,请在下面横线处填入代码完成此程序。

    注意:不改动程序结构,不得增行或删行。

    class ThreadTest implements Runnable

    {

    Thread thrObj;

    public static void main(String args[])

    {

    System.out.println("这是一个通过实现接口创建线程的例子");

    ThreadTest testObj=new ThreadTest();

    testObj.create();

    }

    public void create()

    {

    if(thrObj= =null)

    {

    thrObj=new Thread(this,"myThread");

    ______

    }

    }

    public void run()

    {

    System.out.println("Thread"+throbj.getName()+":"+"在运行!");

    }

    }


    正确答案:thrObj.start();
    thrObj.start(); 解析:本题考查考生对如何通过实现Runnable接口创建线程及使用线程的掌握,这是一道简单应用题。程序中,ThreadTest类实现了Runnable接口,所以ThreadTest类必须重写Runnable接口中的run()方法。在create()方法创建了一个名为thrObj的线程,并调用Thread类中的start()方法启动该线程。语句thrObj=new Thread(this,"myThread");中,this是Thread构造方法的第一个参数,作为该线程的目标对象,它必须实现Runnable接口。第二个参数 myTread为线程的名称。在这种构造方法下,线程thrObj就以目标对象中的run()方法作为自己的run()方法,本例中,目标对象就是ThreadTest类的对象。

  • 第2题:

    在下面程序的下画线处应填入的选项是 public class Test______{ public static void main(String args[]) { Test t=new Test(); Thread tt=new Thread(t); tt.start(); } public void run() { for(int i=0;i<5;i++) System.out.println("i="+i); } }

    A.implements Runnable

    B.extends Thread

    C.implements Thread

    D.extends Runnable


    正确答案:A
    解析:创建线程有两种方法:实现java.lang.Runnahle接口和继承Thread类并重写run()方法。从创建线程实例的语句Thread tt=new Thread(t);可以看出本程序将Test类的实例t作为参数传递给Thread类的构造方法,因此是通过实现Runnable接口创建线程。

  • 第3题:

    3下碳程序段的输出结果是( )。 class Test{ public static void main(Srting args[]){ MyThread t=new MyThread(); t.displayOutput("t has been created"); t.start(); } } class MyThread extends Thread{ public void displayOutput(String s){ SYStem.out.println(s); } public void run() { displayOutput("t is running."); } }

    A.t has been created.

    B.t has been created. t is running.

    C.t is running.

    D.编译出错


    正确答案:A

  • 第4题:

    阅读下面程序 public class Test2 ______ { public static void main(String[] args) { Thread t=new Test2(); t.start(); } public void run() { System.out.println("How are you."); } } 程序中下画线处应填入的正确选项是

    A.implements Thread

    B.extends Runnable

    C.implements Runnable

    D.extends Thread


    正确答案:D

  • 第5题:

    请阅读下面程序,说明该程序创建线程使用的方法是( )。 public class ThreadTest { public static void main(String args[]) { Thread tl=new Thread(new HolloWorld); Thread t2=new Thread(new HolloWorld); tl.start; t2.Start; } } class HolloWorld implements Runnable { int i; public void run { while(true) { System.out.println("HolloWorld"+i++); if(i= =5)break; } } }

    A.继承Thread类

    B.实现Runnable接口

    C.tl.start

    D.t2.start


    正确答案:B
    B。【解析】本题考查线程的创建。在Java中,创建线程有两种方法:①通过实现Runnable接口创建线程。Runnable接口中只定义了一个run方法作为线程体。②通过继承Thread类创建线程,Thread类本身实现了Runnable接口。创建的新的线程不会自动运行,必须调用start方法才能运行。本题中HolloWorld类实现了Runnable接口。

  • 第6题:

    ( 30 )在程序的下划线处应填入的选项是

    public class Test _________{

    public static void main(String args[]){

    Test t = new Test();

    Thread tt = new Thread(t);

    tt.start();

    }

    public void run(){

    for(int i=0;i<5;i++){

    system.out.println( " i= " +i);

    }

    }

    }

    A ) implements Runnable

    B ) extends Thread

    C ) implements Thread

    D ) extends Runnable


    正确答案:A

  • 第7题:

    public class Threads5 {  public static void main (String[] args) {  new Thread(new Runnable() {  public void run() {  System.out.print(”bar”);  } }).start();  }  }  What is the result?() 

    • A、 Compilation fails.
    • B、 An exception is thrown at runtime.
    • C、 The code executes normally and prints “bar”.
    • D、 The code executes normally, but nothing prints.

    正确答案:C

  • 第8题:

    public class A extends Thread {  A() {  setDaemon(true);  }  public void run() {  (new B()).start();  try {  Thread.sleep(60000);  } catch (InterruptedException x) {}  System.out.println(“A done”);  }  class B extends Thread {  public void run() {  try {  Thread.sleep(60000);  } catch (InterruptedException x) {}  System.out.println(“B done”);  }  }  public static void main(String[] args) {  (new A()).start();  }  }   What is the result?()  

    • A、 A done
    • B、 B done
    • C、 A done B done
    • D、 B done A done
    • E、 There is no exception that the application will print anything.
    • F、 The application outputs “A done” and “B done”, in no guaranteed order.

    正确答案:B

  • 第9题:

    1. class MyThread implements Runnable {  2. public void run() {  3. System.out.print("go ");  4. }  5.  6. public static void main(String [] args) {  7. // insert code here  8. t.start(); 9. }  10. }  和如下四句:  Thread t = new MyThread(); MyThread t = new MyThread();  Thread t = new Thread(new Thread());  Thread t = new Thread(new MyThread());  分别插入到第5行,有几个可以通过编译?() 

    • A、0
    • B、1
    • C、2
    • D、3

    正确答案:C

  • 第10题:

    Which two code fragments will execute the method doStuff() in a separate thread?()

    • A、new Thread() {public void run() { doStuff(); }};
    • B、new Thread() {public void start() { doStuff(); }};
    • C、new Thread() {public void start() { doStuff(); }}.run();
    • D、new Thread() {public void run() { doStuff(); }}.start();
    • E、new Thread(new Runnable() {public void run() { doStuff(); }}).start();

    正确答案:D,E

  • 第11题:

    单选题
    public class Threads4 {  public static void main (String[] args) {  new Threads4().go();  }  public void go() {  Runnable r = new Runnable() { public void run() {  System.out.print(”foo”);  }  };  Thread t = new Thread(r);  t.start();  t.start();  }  }  What is the result?()
    A

     Compilation fails.

    B

     An exception is thrown at runtime.

    C

     The code executes normally and prints „foo”.

    D

     The code executes normally, but nothing is printed.


    正确答案: D
    解析: 暂无解析

  • 第12题:

    单选题
    public class A extends Thread {  A() {  setDaemon(true);  }  public void run() {  (new B()).start();  try {  Thread.sleep(60000);  } catch (InterruptedException x) {}  System.out.println(“A done”);  }  class B extends Thread {  public void run() {  try {  Thread.sleep(60000);  } catch (InterruptedException x) {}  System.out.println(“B done”);  }  }  public static void main(String[] args) {  (new A()).start();  }  }   What is the result?()
    A

     A done

    B

     B done

    C

     A done B done

    D

     B done A done

    E

     There is no exception that the application will print anything.

    F

     The application outputs “A done” and “B done”, in no guaranteed order.


    正确答案: D
    解析: 暂无解析

  • 第13题:

    下面程序段的输出结果是 class Test{ public static void main(String args[]){ MyThread t=new MyThread(); t.displayOutput("t has been created)); t.start(); } } class MyThread extends Thread{ public void displayOutput(String s){ System.out.println(s); } public void run(){ displayOutput(t is running."); } }

    A.t has been created.

    B.t has been created. t is running.

    C.t is running.

    D.编译出错


    正确答案:A
    解析:本题考查线程的创建和调用。创建一个新的线程对象后,通过使用 start()方法就可以启动该线程,线程也就处于可运行状态Runnable。Start()方法产生了线程运行需要的系统资源,并调用线程体,也就是run()方法,使得线程可以进入运行状态。程序运行时首先创建一个新的线程对象t,并调用displayOutput(Strings)方法输出t has been created。t.start()方法调用run()方法,输出t is running,所以正确答案为选项A。

  • 第14题:

    下面程序段的输出结果是 classTest{ public static void main(Stringargs[]){ MyThread t=new MyThread(); t.displayOutput(”t has been createD) ”); t.start(); } } Class MyThread extends Thread{ public void displayOutput(Strings){ System.out.println(S); } public void run(){ displayOutput(”t is running.”); } }

    A.thas been created. t is running.

    B.thas been created

    C.t is running.

    D.编译出错


    正确答案:A
    解析:本题考查线程的创建和调用。创建一个新的线程对象后,通过使用start()方法就可以启动该线程,线程也就处于可运行状态Runnable。Start()方法产生了线程运行需要的系统资源,并调用线程体,也就是run()方法,使得线程可以进入运行状态。程序运行时首先创建一个新的线程对象t,并调用displayOutput(Strings)方法输出thas been created。t.start()方法调用run()方法,输出t is running,所以正确答案为选项A。

  • 第15题:

    下面程序段的输出结果是 class Test{ public static void main(String args[]){ MyThread t=new MyThread(); t.displayOutput("t has been createD) "; t.start(); } } class MyThread extends Thread{ public void displayOutput(String s){ System.out.println(s); } public void nm(){ displayOutput("t is running."); }

    A.t has been created. t is running.

    B.t has been created.

    C.t is running.

    D.编译出错


    正确答案:A
    解析:本题考查线程的创建和调用。创建一个新的线程对象后,通过使用start()方法就可以启动该线程,线程也就处于可运行状态Runnable。Start()方法产生了线程运行需要的系统资源,并调用线程体,也就是nm()方法,使得线程可以进入运行状态。,程序运行时首先创建一个新的线程对象t,井调用displayOutput(Strings)方法输出thasbeencreated.t.start()方法调用run()方法,输出tisrunning,所以正确答案为选项A。

  • 第16题:

    阅读下面程序 public class Test implements Runnable { public static void main(String[] args) { ______ t.start(); } public void run() { System.out.println("Hello!"); } } 程序中下画线处应填入的正确选项是

    A.Test t=new Test();

    B.Thread t=new Thread();

    C.Thread t=new Thread(new Test());

    D.Test t=new Thread();


    正确答案:C

  • 第17题:

    下列程序创建了一个线程并运行,请在下划线处填入正确代码。

    public class Try extends Thread{

    public static void main(String args[]){

    Threadt=new Try();

    【 】;

    }

    public void run(){

    System.out.println(“Try!”);

    }

    }


    正确答案:i
    i

  • 第18题:

    public class Threads3 implements Runnable {  public void run() {  System.out.print(”running”);  }  public static void main(String[] args) {  Thread t = new Thread(new Threads3());  t.run();  t.run();  t.start();  }  }  What is the result?() 

    • A、 Compilation fails.
    • B、 An exception is thrown at runtime.
    • C、 The code executes and prints “running”.
    • D、 The code executes and prints “runningrunning”.
    • E、 The code executes and prints “runningrunningrunning”.

    正确答案:E

  • 第19题:

    class TestA {  public void start() { System.out.println(”TestA”); }  }  public class TestB extends TestA {  public void start() { System.out.println(”TestB”); } public static void main(String[] args) {  ((TestA)new TestB()).start();  }  }  What is the result?() 

    • A、 TestA
    • B、 TestB
    • C、 Compilation fails.
    • D、 An exception is thrown at runtime.

    正确答案:B

  • 第20题:

    Which two code fragments will execute the method doStuff() in a separate thread?()

    • A、 new Thread() { public void run() { doStuff(); } }
    • B、 new Thread() { public void start() { doStuff(); } }
    • C、 new Thread() { public void start() { doStuff(); } } .run();
    • D、 new Thread() { public void run() { doStuff(); } } .start();
    • E、 new Thread(new Runnable() { public void run() { doStuff(); } } ).run();
    • F、 new Thread(new Runnable() { public void run() { doStuff(); } }).start();

    正确答案:D,F

  • 第21题:

    public class Threads4 {  public static void main (String[] args) {  new Threads4().go();  }  public void go() {  Runnable r = new Runnable() { public void run() {  System.out.print(”foo”);  }  };  Thread t = new Thread(r);  t.start();  t.start();  }  }  What is the result?() 

    • A、 Compilation fails.
    • B、 An exception is thrown at runtime.
    • C、 The code executes normally and prints „foo”.
    • D、 The code executes normally, but nothing is printed.

    正确答案:B

  • 第22题:

    单选题
    class MyThread extends Thread {  public void run() { System.out.println(“AAA”); }  public void run(Runnable r) { System.out.println(“BBB”); }  public static void main(String[] args) {  new Thread(new MyThread()).start();  }  }   What is the result?()
    A

     AAA

    B

     BBB

    C

     Compilation fails.

    D

     The code runs with no output.


    正确答案: B
    解析: 暂无解析

  • 第23题:

    单选题
    class TestA {  public void start() { System.out.println(”TestA”); }  }  public class TestB extends TestA {  public void start() { System.out.println(”TestB”); } public static void main(String[] args) {  ((TestA)new TestB()).start();  }  }  What is the result?()
    A

     TestA

    B

     TestB

    C

     Compilation fails.

    D

     An exception is thrown at runtime.


    正确答案: C
    解析: 暂无解析