niusouti.com

单选题class Thread2 implements Runnable {  void run() {  System.out.print("go ");  }  public static void main(String [] args) {  Thread2 t2 = new Thread2();  Thread t = new Thread(t2);  t.start();  }  }   结果为()A goB 编译失败C 代码运行,无输出结果D 运行时异常被抛出

题目
单选题
class Thread2 implements Runnable {  void run() {  System.out.print("go ");  }  public static void main(String [] args) {  Thread2 t2 = new Thread2();  Thread t = new Thread(t2);  t.start();  }  }   结果为()
A

go

B

编译失败

C

代码运行,无输出结果

D

运行时异常被抛出


相似考题
更多“单选题class Thread2 implements Runnable {  void run() {  System.out.print("go ");  }  public static void main(String [] args) {  Thread2 t2 = new Thread2();  Thread t = new Thread(t2);  t.start();  }  }   结果为()A goB 编译失败C 代码运行,无输出结果D 运行时异常被抛出”相关问题
  • 第1题:

    阅读下面程序 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

  • 第2题:

    请阅读下面程序,说明该程序创建线程使用的方法是( )。 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接口。

  • 第3题:

    现有:  class ThreadExcept implements Runnable  {  public void run()  {  throw new RuntimeException("exception ");  }  public static void main(Stri_ng  []  args)  {  new  Thread (new  ThreadExcept()).start();  try  {  int x=Integer.parselnt (args [0]);  Thread. sleep (x);  System.out.print("main");  } catch (Exception e)  {  }  }  }  和命令行:  java ThreadExcept l000     哪一个是结果?()    

    • A、main
    • B、编译失败
    • C、main java.lang.RuntimeException: exception
    • D、代码运行,但没有输出

    正确答案:C

  • 第4题:

    现有:   class Thread2 implements Runnable {   void run() {   System.out.print("go ");   }   public static void main(String [] args) {   Thread2 t2 = new Thread2();   Thread t = new Thread(t2);   t.start();   }   }   结果为:()

    • A、 go
    • B、 编译失败
    • C、 代码运行,无输出结果
    • D、 运行时异常被抛出

    正确答案:B

  • 第5题:

    class ThreadBoth extends Thread implements Runnable {  public void run(){ System.out.print("hi "); }  public static void main(String [] args){  Thread t1 = new ThreadBoth();   Thread t2 = new Thread(t1);  t1.run();  t2.run();  }  }  结果为:() 

    • A、hi
    • B、hi hi
    • C、编译失败
    • D、代码运行,但无输出结果

    正确答案:B

  • 第6题:

    现有:  class ThreadBoth extends Threaa implements Runnable  {      public void run()  (System.out.print("hi");  }     public static voicl main (String  []  args)  {     Thread tl=new ThreadBoth():      Thread t2 = new Thread (tl):     tl.run():      t2.run():     }          结果为:()      

    • A、 hi hi
    • B、 hi
    • C、编译失败
    • D、运行时异常被抛出

    正确答案:A

  • 第7题:

    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

  • 第8题:

    单选题
    class Work implements Runnable {  Thread other;   Work(Thread other) { this.other = other; }  public void run() {  try { other.join(); } catch (Exception e) { }  System.out.print("after join ");  } }  class Launch {  public static void main(String [] args) {  new Thread(new Work(Thread.currentThread())).start();  System.out.print("after start ");  } }  结果为:()
    A

    after join

    B

    after start

    C

    after join after start

    D

    after start after join


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

  • 第9题:

    单选题
    现有:  class ThreadExcept implements Runnable  {  public void run()  {  throw new RuntimeException("exception ");  }  public static void main(Stri_ng  []  args)  {  new  Thread (new  ThreadExcept()).start();  try  {  int x=Integer.parselnt (args [0]);  Thread. sleep (x);  System.out.print("main");  } catch (Exception e)  {  }  }  }  和命令行:  java ThreadExcept l000     哪一个是结果?()
    A

    main

    B

    编译失败

    C

    main java.lang.RuntimeException: exception

    D

    代码运行,但没有输出


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

  • 第10题:

    单选题
    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


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

  • 第11题:

    单选题
    现有:  class Thread2 implements Runnable  {      void run()  {      System.out.print ("go¨);      }      public static void main(String  []  args)  {        Thread2 t2=new Thread2();      Thread t=new Thread(t2);      t.start();      }      }      结果为:()
    A

    go

    B

    运行时异常被抛出

    C

    代码运行,无输出结果

    D

    编译失败


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

  • 第12题:

    单选题
    class ThreadBoth extends Thread implements Runnable {  public void run(){ System.out.print("hi "); }  public static void main(String [] args){  Thread t1 = new ThreadBoth();   Thread t2 = new Thread(t1);  t1.run();  t2.run();  }  }  结果为:()
    A

    hi

    B

    hi hi

    C

    编译失败

    D

    代码运行,但无输出结果


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

  • 第13题:

    下列程序的输出结果是______。 class T44 implements Runnable { public void run() { System.out.print in (Thread.currentThread ( ).getName ( ) + "运行" ); } } public class ex44 { public static void main(String[] args) { Thread t1 = new Thread(new T44(), "t1"); Thread t2 = new Thread(new T44 () , "t2"); t1 .setPriority(Thread. MAX_PRIORITY); t2.setPriority(Thread.MIN_PRIORITY); t2. start (); t1 .start (); } }

    A.t1 运行 t2 运行

    B.t2 运行 t1 运行

    C.t1 运行 t1 运行

    D.t2 运行 t2 运行


    正确答案:A

  • 第14题:

    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

  • 第15题:

    class ThreadExcept implements Runnable {   public void run() { throw new RuntimeException("exception "); }   public static void main(String [] args) {   new Thread(new ThreadExcept()).start();   try {   int x = Integer.parseInt(args[0]);   Thread.sleep(x);   System.out.print("main ");    } catch (Exception e) { }      }  }   和命令行:  java ThreadExcept 1000    哪一个是结果?()  

    • A、 main
    • B、 编译失败
    • C、 代码运行,但没有输出
    • D、 main java.lang.RuntimeException:exception

    正确答案:D

  • 第16题:

    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

  • 第17题:

    class Work implements Runnable {  Thread other;   Work(Thread other) { this.other = other; }  public void run() {  try { other.join(); } catch (Exception e) { }  System.out.print("after join ");  } }  class Launch {  public static void main(String [] args) {  new Thread(new Work(Thread.currentThread())).start();  System.out.print("after start ");  } }  结果为:()

    • A、after join
    • B、after start
    • C、after join after start
    • D、after start after join

    正确答案:D

  • 第18题:

    class Order implements Runnable {    public void run ()  {  try { Thread.sleep (2000) ;  } catch (Exception e)    System.out.print("in") ;  public static void main (String [] args)  {    Thread t = new Thread (new Order ()) ;    t.start () ;  System.out.print ("pre ") ;  try { t.join () ;  } catch (Exception e)  { }    System.out.print ("post") ;   可产生哪两项结果?()  

    • A、 pre in post
    • B、 pre in
    • C、 in post pre
    • D、 in pre post
    • E、 pre post in

    正确答案:A,D

  • 第19题:

    单选题
    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”.


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

  • 第20题:

    单选题
    现有:   class Thread2 implements Runnable {   void run() {   System.out.print("go ");   }   public static void main(String [] args) {   Thread2 t2 = new Thread2();   Thread t = new Thread(t2);   t.start();   }   }   结果为:()
    A

     go

    B

     编译失败

    C

     代码运行,无输出结果

    D

     运行时异常被抛出


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

  • 第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.


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

  • 第22题:

    单选题
    现有:  class ThreadBoth extends Threaa implements Runnable  {      public void run()  (System.out.print("hi");  }     public static voicl main (String  []  args)  {     Thread tl=new ThreadBoth():      Thread t2 = new Thread (tl):     tl.run():      t2.run():     }          结果为:()
    A

     hi hi

    B

     hi

    C

    编译失败

    D

    运行时异常被抛出


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

  • 第23题:

    多选题
    class Order implements Runnable {  public void run() {  try { Thread.sleep(2000); } catch (Exception e) { }  System.out.print("in ");  }  public static void main(String [] args) {  Thread t = new Thread(new Order());  t.start();  System.out.print("pre ");  try { t.join(); } catch (Exception e) { }  System.out.print("post ");  } }  可产生哪两项结果?()
    A

    in pre

    B

    pre in

    C

    in pre post

    D

    pre in post


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

  • 第24题:

    单选题
    现有:   class ThreadExcept implements Runnable {   public void run() { throw new RuntimeException("exception "); }   public static void main(String [] args) {   new Thread(new ThreadExcept()).start();   try {   int x = Integer.parseInt(args[0]);   Thread.sleep(x);   System.out.print("main ");  } catch (Exception e) { }  }   }   和命令行:  java ThreadExcept 1000   哪一个是结果?()
    A

     main

    B

     编译失败

    C

     代码运行,但没有输出

    D

     main java.lang.RuntimeException: exception


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