更多"通过实现Runnable接口创建线程,请在画线处加入正确的代码完成此程"的相关试题:
[填空题]通过实现Runnable接口创建线程,请在画线处加入正确的代码完成此程序 【9】 。
public class ThreadTest
public static void main(String args[ ]
Thread t1 = new Thread(new Hello( )
Thread t2 = new Thread(new Hello( )
___________;
t2.start( );
class Hello implements Runnable
int i;
public void run( )
while (true)
System.out.println("Hello"+i++
if(i==5) break;
[填空题]通过实现Runnable接口创建线程,请在画线处加入正确的代码完成此程序 【9】 。
public class ThreadTest
{
public static void main(String args[ ]
{
Thread t1 = new Thread(new Hello( )
Thread t2 = new Thread(new Hello( )
___________;
t2.start( );
}
}
class Hello implements Runnable
{
int i;
public void run( )
{
while (true)
{
System.out.println("Hello"+i++
if(i==5) break;
}
}
}
[填空题]通过实现Runnable接口创建线程,请在画线处加入正确的代码完成此程序______。
publicclass ThreadTest
publicstaticvoid main(Stringargs[])
Threadt1=newThread(newHello( )):
Threadt2=newThread(newHellO( ));
T2.start( );
classHelloimplementsRunnable
intI;
publicvoidIUB( )
while(true)
System.out.println(“Hello”+i++);
If(i==5)break;
[填空题]通过实现Runnable接口创建线程,请在画线处加入正确的代码完成此程序______。
publicclass ThreadTest
{
publicstaticvoid main(Stringargs[])
{
Threadt1=newThread(newHello( )):
Threadt2=newThread(newHellO( ));
T2.start( );
}
}
classHelloimplementsRunnable
{
intI;
publicvoidIUB( )
{
while(true)
{
System.out.println(“Hello”+i++);
If(i==5)break;
}
}
}
[填空题]通过实现Runnable接口创建线程,请在画线处加入正确的代码完成此程序_________。
public class ThreadTest
public static void main(String args[])
Thread t1=new Thread(new Hello( )):
Thread t2=new Thread(new Hello( ));
________;
t2.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 ++);
}
}
[简答题]通过实现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( )+":"+"在运行!");
}
}
[简答题]通过实现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( )+":"+"在运行!");
[填空题]从对象流中读取对象,请在画线处加入代码完成此程序 【10】 。
import java.util.*;
import java.io.*;
public class UnSerializeDate
{
Date d = null;
UnSerializeDate( )
{
try{
FileInputStream f = new FileInputStream("data.ser");
______;
d = (Date) s.readObject( );
f.close( );
}
catch(Exception e)
{
e.printStackTrace( );
}
}
public static void main(String args[ ])
{
UnSerializeDate a = new UnSerializeDate( );
System.out.println("The date read is :"+a.d.toString( ));
}
}
[填空题]从对象流中读取对象,请在画线处加入代码完成此程序 【10】 。
import java.util.*;
import java.io.*;
public class UnSerializeDate
Date d = null;
UnSerializeDate( )
try
FileInputStream f = new FileInputStream("data.ser");
______;
d = (Date) s.readObject( );
f.close( );
catch(Exception e)
e.printStackTrace( );
public static void main(String args[ ])
UnSerializeDate a = new UnSerializeDate( );
System.out.println("The date read is :"+a.d.toString( ));
[单项选择]下列程序通过实现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(m
B. new Thread()
C. new Thread(m
D. Thread(m
[单项选择]下列程序从标准输入设备——键盘读入一个字符,然后输出到屏幕。要想完成此功能,画线处应该填入的语句为______。
import java. io. * ;
public class Test
public static void main(String args[])
char ch;
try
______;
System. out. println(ch);
catch(IOException e)
e. printStackTrace( );
A. ch=System. in. read();
B. ch=(char)System. in. read();
C. ch=(char)System. in. readln();
D. ch=(int)System. in. read();
[单项选择]下列程序从标准输入设备——键盘读入一个字符,然后再输出到屏幕。要想完成此功能,画线处应该填入的语句为( )。
import java.io.*;
public class Test
public static void main(String args[ ])
char ch;
try
______;
System.out.println(ch);
catch(IOException e)
e.printStackTrace( );
A. ch= System.in.read();
B. ch=(char)Systcm in.read();
C. ch=(char)System.in.readln();
D. ch=(int)System in.read();