niusouti.com

单选题Runnable r = new Runnable() {  public void run() {  System.out.print(”Cat”);  }  };  Threadt=new Thread(r) {  public void run() {  System.out.print(”Dog”);  }  };  t.start();  What is the result?()ACatBDogCCompilation fails.DThe code runs with no outpu

题目
单选题
Runnable r = new Runnable() {  public void run() {  System.out.print(”Cat”);  }  };  Threadt=new Thread(r) {  public void run() {  System.out.print(”Dog”);  }  };  t.start();  What is the result?()
A

 Cat

B

 Dog

C

 Compilation fails.

D

 The code runs with no output.

E

 An exception is thrown at runtime.


相似考题
参考答案和解析
正确答案: C
解析: 暂无解析
更多“单选题Runnable r = new Runnable() {  public void run() {  System.out.print(”Cat”);  }  };  Threadt=new Thread(r) {  public void run() {  System.out.print(”Dog”);  }  };  t.start();  What is the result?()A  CatB  DogC  Compilation fails.D  The code runs with ”相关问题
  • 第1题:

    Runnable r = new Runnable() {  public void run() {  System.out.print(”Cat”);  }  };  Threadt=new Thread(r) {  public void run() {  System.out.print(”Dog”);  }  };  t.start();  What is the result?() 

    • A、 Cat
    • B、 Dog
    • C、 Compilation fails.
    • D、 The code runs with no output.
    • E、 An exception is thrown at runtime.

    正确答案:B

  • 第2题:

    现有:   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

  • 第3题:

    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

  • 第4题:

    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

  • 第5题:

    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

  • 第6题:

    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

  • 第7题:

    单选题
    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
    解析: 暂无解析

  • 第8题:

    单选题
    class Base {  Base() { System.out.print(“Base”); }  }  public class Alpha extends Base {  public static void main( String[] args ) {  new Alpha();  new Base();  }  }  What is the result?()
    A

     Base

    B

     BaseBase

    C

     Compilation fails.

    D

     The code runs with no output.

    E

     An exception is thrown at runtime.


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

  • 第9题:

    单选题
    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
    解析: 暂无解析

  • 第10题:

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


    正确答案: 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题:

    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

  • 第14题:

    public class TestOne implements Runnable {  public static void main (String[] args) throws Exception {  Thread t = new Thread(new TestOne());  t.start();  System.out.print(”Started”);  t.join();  System.out.print(”Complete”);  }  public void run() {  for (int i= 0; i< 4; i++) {   System.out.print(i);  }  }  }  What can be a result?()

    • A、 Compilation fails.
    • B、 An exception is thrown at runtime.
    • C、 The code executes and prints “StartedComplete”.
    • D、 The code executes and prints “StartedComplete0123”.
    • E、 The code executes and prints “Started0l23Complete”.

    正确答案:E

  • 第15题:

    现有:  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

  • 第16题:

    class Base {  Base() { System.out.print(“Base”); }  }  public class Alpha extends Base {  public static void main( String[] args ) {  new Alpha();  new Base();  }  }  What is the result?()  

    • A、 Base
    • B、 BaseBase
    • C、 Compilation fails.
    • D、 The code runs with no output.
    • E、 An exception is thrown at runtime.

    正确答案:B

  • 第17题:

    Given that a static method doIt() in a class Work represents work to be done, what block of code will succeed in starting a new thread that will do the work?   CODE BLOCK a:   Runnable r = new Runnable() {   public void run() {   Work.doIt();   }   };   Thread t = new Thread(r);   t.start();   CODE BLOCK b:   Thread t = new Thread() {  public void start() {   Work.doIt();  }  };   t.start();   CODE BLOCK c:   Runnable r = new Runnable() {   public void run() {   Work.doIt();   }   };   r.start();  CODE BLOCK d:   Thread t = new Thread(new Work());   t.start();   CODE BLOCK e:   Runnable t = new Runnable() {   public void run() {   Work.doIt();   }   };   t.run();  

    • A、Code block a.
    • B、Code block B.
    • C、Code block c.
    • D、Code block d.
    • E、Code block e.

    正确答案:A

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


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

  • 第19题:

    单选题
    Runnable r = new Runnable() {  public void run() {  System.out.print(”Cat”);  }  };  Threadt=new Thread(r) {  public void run() {  System.out.print(”Dog”);  }  };  t.start();  What is the result?()
    A

     Cat

    B

     Dog

    C

     Compilation fails.

    D

     The code runs with no output.

    E

     An exception is thrown at runtime.


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

  • 第20题:

    单选题
    public class TestOne implements Runnable {  public static void main (String[] args) throws Exception {  Thread t = new Thread(new TestOne());  t.start();  System.out.print(”Started”);  t.join();  System.out.print(”Complete”);  }  public void run() {  for (int i= 0; i< 4; i++) {   System.out.print(i);  }  }  }  What can be a result?()
    A

     Compilation fails.

    B

     An exception is thrown at runtime.

    C

     The code executes and prints “StartedComplete”.

    D

     The code executes and prints “StartedComplete0123”.

    E

     The code executes and prints “Started0l23Complete”.


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

  • 第21题:

    多选题
    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();


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

  • 第22题:

    多选题
    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();


    正确答案: C,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题:

    单选题
    Given that a static method doIt() in a class Work represents work to be done, what block of code will succeed in starting a new thread that will do the work?   CODE BLOCK a:   Runnable r = new Runnable() {   public void run() {   Work.doIt();   }   };   Thread t = new Thread(r);   t.start();   CODE BLOCK b:   Thread t = new Thread() {  public void start() {   Work.doIt();  }  };   t.start();   CODE BLOCK c:   Runnable r = new Runnable() {   public void run() {   Work.doIt();   }   };   r.start();  CODE BLOCK d:   Thread t = new Thread(new Work());   t.start();   CODE BLOCK e:   Runnable t = new Runnable() {   public void run() {   Work.doIt();   }   };   t.run();
    A

    Code block a.

    B

    Code block B.

    C

    Code block c.

    D

    Code block d.

    E

    Code block e.


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