下列程序创建了一个线程并运行,请在下划线处填入正确代码。public class Try extends Thread{public static void main(String args[]){Threadt=new Try();【 】;}public void run(){System.out.println(“Try!”);}}

下列程序创建了一个线程并运行,请在下划线处填入正确代码。

public class Try extends Thread{

public static void main(String args[]){

Threadt=new Try();

【 】;

}

public void run(){

System.out.println(“Try!”);

}

}


相关考题:

( 28 )阅读下面程序1 public class Try extends Thread{2 public static void main(String args[ ]){3 Try t = new Try( );4 t.start( );5 }67 public void run( int j){8 int i = 0;9 while(i5){10 System.out.println(" 祝你成功! ");11 i++;12 }13 }14 }该程序要求打印 5 行 “ 祝你成功! ” ,必须改正程序中的某行代码,程序才能完成。选择正确的修改是A )将第 1 行的 extends Thread 改为 implements RunnableB )将第 3 行的 new Try() 改为 new Thread()C )将第 4 行 t.start() 改为 start(t)D )将第 7 行的 public void run( int j) 改为 public void run()

通过实现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 ++);}}

下面程序的功能是创建一个显示5个“Hello!”的线程并启动运行。请将程序补充完整。public class ThreadTest extends Thread {public static void main(String args[]) {ThreadTest t=new ______;t.start();}public void run() {int i=0;while(true) {System.out.println("Hello!");if(i++==4)break;}}}

下列程序构造了一个 Swing Applet ,请在下划线处填入正确的代码Import javax.swing.*;Import java.awt.*;Public class SwingApplet extends 【 13 】 {Jlabel l = new Jlabel ( “ This is a Swing Applet. ” );Public void init(){Container contentPane = getContentPane();contentPane.add(1);}}

请在下划线处填入代码,是程序正常运行并且输出 “ Hello! ”Class Test 【 15 】 {Public static void main (String[] arge){Test t = new Test();t.start();}Public void run(){System.out.println( “ Hello! ” );}

创建线程对象,要传递代码与数据,而传递代码与数据有两种方法,一是通过继承Thread类,二是向Thread类传递一个Runnable对象。请在下面程序的每条横线处填写一个语句,使程序的功能完整。注意:请勿改动main()主方法和其他已有的语句内容,仅在横线处填入适当的语句。public class TestThread{public static void main(String args[ ]){MyThread t=new MyThread();_______________________}}class MyThread_____________Thread{_____________________{for(int i=0;i10;i++){System.out.println(" " +i);}}}

通过实现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()+":"+"在运行!");}}

阅读下面程序 1 public class Try extends Thread{ 2 public static void main(String args[]){ 3 Try t=new Try(); 4 t.start(); 5 } 6 7 public void run(int j){ 8 int i=0; 9 while(i<5){ 10 System.out.println(“祝你成功!”); 11 i++; 12 } 13 } 14 } 该程序要求打印5行“祝你成功!”,必须改正程序中的某行代码,程序才能完成。选择正确的修改是A.将第1行的extends Thread改为implements RunnableB.将第3行的new Try()改为new Thread()C.将第4行t.start()改为start(t)D.将第7行的public void run(int j)改为public void run()

阅读下面程序 public class Test2______ { public static void main(String[] args){ Thread t=new Test2(); t. start(); } public void run(){ System. out. priatln("How are you. "); } } 在程序下画线处填入的正确的选项是A.implements ThreadB.extends RunnableC.implements RunnableD.extends Thread

阅读下面程序 1 public class Try extends Thread { 2 public static void main(String args[]) { 3 Try t=new Try(); 4 t.start(); 5 } 6 7 public void run(int j) { 8 int i=0; 9 while(i<5) { 10 System.out.println("祝你成功!"); 11 i++: 12 } 13 } 14 } 该程序若能打印5行“祝你成功!”,必须改正程序中的某行代码,选择正确的修改是A.将第1行的extends Thread改为implements RunnableB.将第3行的new Try()改为new Thread()C.将第4行的t.start()改为start(t)D.将第7行的public void run(int j)改为public void run()

下列程序的功能是创建一个显示5个“Hello!”的线程并启动运行,试将程序补充完整。public class ThreadTest extends Thread{public static void main(String args[ ]){ThreadTest t=new______;t.start( );}public void run( ){int i=0;while(true){System.out.println("Hello!");if(i++==4)break;}}

下列程序的运行结果是______。 class A implements Runnable { int a; iht i = 2; A(int x) { a = x; } public void run() { while(i > 0) { System.out.println("线程" + a); i--; } } } public class Testl3 { public static void main(String[] args) { Thread a1 = new Thread(new A(1)); Thread a2 = new Thread(new A(2)); a1.start(); a2.start(); } }A.线程1 线程1 线程2 线程2B.线程1 线程2C.线程1 线程2 线程1 线程2D.线程1 线程1 线程1 线程1

下列程序的运行结果是______。 Class C14 implements Runnable { private int i; public C14(int n) { this.i = n; } public void run{) { try { Thread.currentThread().sleep(i); } catch(InterruptedException ie) { System.err.println(ie.tString()); } System.out.println("线程" + Thread.currentThread() .getName + "睡眠了" + i + "毫秒结束"); } } public class Testl4 { public static void main(String[] args) { Thread t = new Thread(new C14(300), "t"); t.start(); } }A.线程t睡眠了300毫秒结束B.线程Thread-0睡眠了300毫秒结束C.线程t睡眠了i毫秒结束D.线程Thread-0睡眠了i毫秒结束

下列程序创建了-个线程并运行,横线处应填入的正确代码是( )。 A.t.startB.t.classSX 下列程序创建了-个线程并运行,横线处应填入的正确代码是( )。A.t.startB.t.classC.t.threadD.t.static

在程序中,DataPool是一个数据池,能存放一个血型数据,线程a和线程b负责向其中存放数据,一次只能有一个线程向其中存放数据,数据放入DataPool以后,该线程随机休眠一段时间,让另外一个线程运行,请将程序补充完整。注意:请勿修改main()主方法和其他已有语句内容,仅在横线处填入适当语句。class PutData extends Thread{DataPool s;int c;String name;public PutData(DataPool s,String name){this.s=s;this.name=name;}public void run(){for(int i=0;i<10000000;i++){c=(int)(Math.random()*10);s.setData(c);System.out.println(name+":push"+c);try{______((int) (Math.random()*1000));//休眠}catch(InterruptedException e){}}}}class DataPool{private int data=0;public ______void setData(int d){data=d;}}public class simple{public static void main(String[] args){DataPool s=new DataPool();PutData a=new PutData(s,"Thread a");PutData b=new PutData(s,"Thread b");a.start();b.start();}}

下列程序创建了一个线程并运行,横线处应填入的正确代码是( )。 public class Try extends Thread{ public static void main(String args[]){ Thread t=new Try; ; } public void runf System.out.println(”Try!"); } }A.t.startB.t.classC.t.threadD.t.static

3阅读下面程序 1 public class Try extends Thread{ 2 public static void main(String args[ ]){ 3 Try t = new Try( ); 4 t.start( ); 5 } 6 7 public void run( int j){ 8 int i = 0; 9 while(i<5) { 10 System.out.pfintln("祝你成功"); 11 i++; 12 } 13 } 14 } 该程序要求打印5行“祝你成功”必须改正程序中的某行代码,程序才能完成。选择正确的修改是( )。A.将第1行的extends Thread改为implements RunnableB.将第3行的new Try()改为new Thread()C.将第4行t.sta.rt()改为start(t)D.将第7行的publ void run(int j)改为public void run()

要下列Java Applet程序完整并能够正确运行,横线处应填入的内容是( )。 A.extends Thread 要下列Java Applet程序完整并能够正确运行,横线处应填入的内容是( )。A.extends ThreadB.extends AppletC.extends CharD.extends Float

阅读下面程序 public class Test2 ______ { public static void main(String[] args) { Thread t=new Test2(); t.start(); } public void run() { System.out.println("How are you."); } } 程序中下画线处应填入的正确选项是A.implements ThreadB.extends RunnableC.implements RunnableD.extends Thread

下列程序通过实现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)

请在下划线处填入代码,使程序能够正确运行。import java .awt.*;import java .applet.*;public class SayHi extends Applet{public void【 】(Graphics g){g .drawString(“Hi!”20,20);}}

下列程序构造了一个SwingApplet,请在下划线处填入正确的代码:import javax.swing0*;impon java.awt.*;public class SwingAppletextends______{JLabell=newJLabel("ThisisaSwingApplet.");publicvoidinit(){ContainercontentPane=getContentPane();contentPane.add(1);}}

( 8 )在下列 Java applet 程序的横线处填入代码,使程序完整并能够正确运行。Import java. awt. *;Import java. applet. *;Public class Greeting extends applet{Public void 【 8 】 (Graphics g) {g.drawSting( “ how are you! ” ,10,10);}}

( 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

( 15 )在下列 Java Applet 程序的下划线处填入代码,使程序完整并能够正确运行。import java.applet.*;import java.awt.*;public class HelloWorld 【 15 】 {public void paint(Graphics g){g.drawString( " Hello World! " ,25,25);}}

public class A extends Thread {  A() {  setDaemon(true);  }  public void run() {  (new B()).start();  try {  Thread.sleep(60000);  } catch (InterruptedException x) {}  System.out.println(“A done”);  }  class B extends Thread {  public void run() {  try {  Thread.sleep(60000);  } catch (InterruptedException x) {}  System.out.println(“B done”);  }  }  public static void main(String[] args) {  (new A()).start();  }  }   What is the result?()  A、 A doneB、 B doneC、 A done B doneD、 B done A doneE、 There is no exception that the application will print anything.F、 The application outputs “A done” and “B done”, in no guaranteed order.

单选题public class A extends Thread {  A() {  setDaemon(true);  }  public void run() {  (new B()).start();  try {  Thread.sleep(60000);  } catch (InterruptedException x) {}  System.out.println(“A done”);  }  class B extends Thread {  public void run() {  try {  Thread.sleep(60000);  } catch (InterruptedException x) {}  System.out.println(“B done”);  }  }  public static void main(String[] args) {  (new A()).start();  }  }   What is the result?()A A doneB B doneC A done B doneD B done A doneE There is no exception that the application will print anything.F The application outputs “A done” and “B done”, in no guaranteed order.