网友您好, 请在下方输入框内输入要搜索的题目:
题目内容
(请给出正确答案)
单选题
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
参考答案
参考解析
解析:
暂无解析
更多 “单选题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 0B 1C 2D 3” 相关考题
考题
下面程序段的输出结果是______。 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 display Output(String s){ System.out,println(s); } public void run( ){ displayOutput("t is running"); } }A.t has been created t is runningB.t has been createdC.t is runningD.编译错误
考题
下面程序创建了一个线程并运行,请填空,使程序完整。public class ThreadTest {public static void main (String[] args) {Hello h=Hew Hello ();【 】t.start ();}}class Hello implements Runnable {int i;public void run () {while(true) {System.out.println("Hello" +i++);if(i==5) break;}}}
考题
通过实现Rmmable接口创建线程,请在下面横线处填写代码完成此程序。public class ThreadTest{public static void main(String args []){Thread testObj1 = new Thread (new Hello ());Thread testObj2 = new Thread (new Hello ());testObj 2.start ( );}}class Hello implements Runnable{int j;public void run(){System.out.println("Hello" + j ++);}}
考题
下列关于Test类的定义中,正确的是______。A) class Test implements Runnabte{public void run(){}public void someMethod(){}B) class Test implements Rnuuable{public void run();}C) class Test implements Rnuuable{public void someMethod();}D) class Test implements Rnuuable{public void someMethod();{}}A.B.C.D.
考题
下列哪个方法可用于创建一个可运行的类? ( )A.public class X implements Runable {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 implements Runable {protected void run(){.....}}
考题
通过实现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()+":"+"在运行!");}}
考题
下面程序段的输出结果是 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.编译出错
考题
在下面程序的下画线处应填入的选项是 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 RunnableB.extends ThreadC.implements ThreadD.extends Runnable
考题
下列关于Test类的定义中,正确的是( )。A.class Test implements Runnable{ public void run{} Dublic void someMethod[]{} }B.class Test implements Runnable( puIblic void run; }C.class Test implements Runnable( Dublic void someMethod[]; }D.class Test implements Runnable( public void someMethod{} }
考题
下列程序通过实现Runnable接口创建一个线程,选择正确的语句填入程序的横线处。 class MyRun implements Runnable { String str; MyRun(String s) { str = s; } public void run() System.out.println(str); } } public class ex40 { public static void main(String[] args) { String name = "实现阶段Runnable 接口"; MyRun my = new MyRun(name); Thread th = th. start ( ); } }A.new MyRun(my)B.new Thread()C.new Thread(my)D.Thread(my)
考题
( 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;i5;i++){system.out.println( " i= " +i);}}}A ) implements RunnableB ) extends ThreadC ) implements ThreadD ) extends Runnable
考题
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”.
考题
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、 AAAB、 BBBC、 Compilation fails.D、 The code runs with no output.
考题
interface Data { public void load(); } abstract class Info { public abstract void load(); } Which class correctly uses the Data interface and Info class?() A、 public class Employee extends Info implements Data { public void load() { /*do something*/ } }B、 public class Employee implements Info extends Data { public void load() { /*do something*/ } }C、 public class Employee extends Info implements Data { public void load() { /*do something */ } public void Info.load() { /*do something*/ } }D、 public class Employee implements Info extends Data { public void Data.load() { /*dsomething */ } public void load() { /*do something */ } }E、 public class Employee implements Info extends Data { public void load() { /*do something */ } public void Info.load(){ /*do something*/ } }F、 public class Employee extends Info implements Data{ public void Data.load() { /*do something*/ } public void Info.load() { /*do something*/ } }
考题
下列代码正确的是哪项?() A、 public class Session implements Runnable, Clonable{ public void run ();public Object clone () ; }B、 public class Session extends Runnable, Cloneable { public void run() {/*dosomething*/} public Object clone() {/*make a copy*/} }C、 public abstract class Session implements Runnable, Clonable { public void run() {/*do something*/} public Object clone() {/*make a copy*/} }D、 public class Session implements Runnable, implements Clonable { public void run() {/*do something*/} public Object clone() {/*make a copy*/} }
考题
Which method must be defined by a class implementing the java.lang.Runnable interface? () A、 void run()B、 public void run()C、 public void start()D、 void run(int priority)E、 public void run(int priority)F、 public void start(int priority)
考题
现有: 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 hiB、 hiC、编译失败D、运行时异常被抛出
考题
单选题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”.
考题
单选题Which method must be defined by a class implementing the java.lang.Runnable interface? ()A
void run()B
public void run()C
public void start()D
void run(int priority)E
public void run(int priority)F
public void start(int priority)
考题
单选题下列代码正确的是哪项?()A
public class Session implements Runnable, Clonable{ public void run ();public Object clone () ; }B
public class Session extends Runnable, Cloneable { public void run() {/*dosomething*/} public Object clone() {/*make a copy*/} }C
public abstract class Session implements Runnable, Clonable { public void run() {/*do something*/} public Object clone() {/*make a copy*/} }D
public class Session implements Runnable, implements Clonable { public void run() {/*do something*/} public Object clone() {/*make a copy*/} }
考题
单选题interface Data { public void load(); } abstract class Info { public abstract void load(); } Which class correctly uses the Data interface and Info class?()A
public class Employee extends Info implements Data { public void load() { /*do something*/ } }B
public class Employee implements Info extends Data { public void load() { /*do something*/ } }C
public class Employee extends Info implements Data { public void load() { /*do something */ } public void Info.load() { /*do something*/ } }D
public class Employee implements Info extends Data { public void Data.load() { /*dsomething */ } public void load() { /*do something */ } }E
public class Employee implements Info extends Data { public void load() { /*do something */ } public void Info.load(){ /*do something*/ } }F
public class Employee extends Info implements Data{ public void Data.load() { /*do something*/ } public void Info.load() { /*do something*/ } }
考题
单选题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
hiB
hi hiC
编译失败D
代码运行,但无输出结果
考题
单选题现有: 1. interface Animal { 2. void eat(); 3. } 4. 5. // insert code here 6. 7. public class HouseCat extends Feline { 8. public void eat() { } 9. } 和五个声明: abstract class Feline implements Animal { } abstract class Feline implements Animal { void eat(); } abstract class Feline implements Animal { public void eat(); } abstract class Feline implements Animal { public void eat() { } } abstract class Feline implements Animal { abstract public void eat(); } 分别插入到第5行,有几个可以通过编译?()A
0B
1C
2D
3
考题
多选题Which two code fragments will execute the method doStuff() in a separate thread?()Anew Thread() { public void run() { doStuff(); } }Bnew Thread() { public void start() { doStuff(); } }Cnew Thread() { public void start() { doStuff(); } } .run();Dnew Thread() { public void run() { doStuff(); } } .start();Enew Thread(new Runnable() { public void run() { doStuff(); } } ).run();Fnew Thread(new Runnable() { public void run() { doStuff(); } }).start();
考题
单选题现有: interface Animal { void eat () ; } //insert code here public class HouseCat extends Feline { public void eat() { } } 和五个申明 abstract class Feline implements Animal { } abstract class Feline implements Animal { void eat () ; } abstract class Feline implements Animal { public void eat();} abstract class Feline implements Animal { public void eat() {} } abstract class Feline implements Animal { abstract public void eat();} 结果为:()A
1B
2C
3D
4
考题
单选题现有: 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 hiB
hiC
编译失败D
运行时异常被抛出
考题
单选题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
AAAB
BBBC
Compilation fails.D
The code runs with no output.
热门标签
最新试卷