class X implements Runnable{public static void main(String args[]){/* Missing code? */}public void run() {}}哪一行代码适合启动线程?
A: Thread t = new Thread(X);
B: Thread t = new Thread(X);t.start();
C: X run = new X();Thread t = new Thread(run);t.start();
D: Thread t = new Thread();x.run();
A: Thread t = new Thread(X);
B: Thread t = new Thread(X);t.start();
C: X run = new X();Thread t = new Thread(run);t.start();
D: Thread t = new Thread();x.run();
举一反三
- Given: 1. public class Foo implements Runnable { 2. public void run (Thread t) { 3. System.out.println("Running."); 4. } 5. public static void main (String[] args) { 6. new Thread (new Foo()).start(); 7. } 8. } What is the result?
- 阅读下面的程序,分析代码是否能编译通过。如果能编译通过,请列出运行的结果;如果不能编译通过,请说明原因。class RunHandler {public void run() {System.out.println("run");}}public class Read01 {public static void main(String [] args) {Thread t = new Thread(new RunHandler( ));t.start( );}}
- 下列程序创建了一个线程并运行,请在下画线处填入正确代码。 public class Try extends Thread public static void main(String args[]) Thread t=new Try(); ______; public void run() System.out.printin("Try!");
- 下列哪个方法可用于创建一个可运行的类X? A: public class X implements Runnable{ public void run(){......} } B: public class X implements Thread{ public void run(){......} } C: public class X implements Thread{ public int run(){......} } D: public class X extends Runnable{ public void run(){......} }
- 下列哪个方法可用于创建一个可运行的类() A: public class X implements Runnable{public void run() {……}} B: public class X extends Thread{public void run() {……}} C: public class X extends Thread{public int run() {……}} D: public class X implements Runnable{protected void run() {……}}