下列哪个方法可用于创建一个可运行的类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 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() {……}}
- 下列关于Test类的定义代码中,正确的是______。 A: class Test implements Runnable { public void run() {} public void someMethod() {} } B: class Test implements Runnable { public void run(); } C: class Test implements Runnable { public void someMethod(); } D: class Test implements Runnable { public void someMethod() {} }
- 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();
- 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?
- interface A{ void x(); } class B implements A{ public void x(){} public void y(){} } class C extends B{ public void x(){System.out.println("C");} } public class Test{ public static void main(String args[]){ B b=new B(); B c=new C(); b.x(); c.y(); } } A: 程序运行错误 B: 程序没有输出结果 C: 程序输出C。 D: class B implements A 编译错误 E: c.y();编译错误