更多"通过实现Runnable接口创建线程,请在下面横线处填入代码完成此程序"的相关试题:
[填空题]通过实现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 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
[填空题]通过实现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:
[填空题]从对象流中读取对象,请在下面横线处填写代码完成此程序。
import java.util. *;
import java. io. *;
public class UnSerializeDate
{
date d = null;
UnSerializeDate ( )
{
try
{
FileInputStream f1 = new FileInputStream("date.ser");
d = (Date) s. readobject ( );
f1,close( );
}
catch (Exceptin e)
{
e. printStackTrace ( );
}
}
public static main(String args [] )
{
System.out.println("The date read is: "+ a.d.toString( ));
}
}
[填空题]若要在D盘根目录下生成一个名为mydir的文件夹,请在下面横线处填入代码完成此程序。
import java.io.*;
public class FileTest
public static void main(String args[])
【7】
File fileObject1 = new File("Filel.txt");
File fileObject2 = new File("d://mydir", "File2.txt");
System.out.println(fileObject2);
try
dirObject.mkdir( );
catch(SecurityException e)
try
fileObject1.createNewFile( );
fileObject2.createNewFilei);
catch(IOException e)
[单项选择]在下列程序的横线处填入正确的语句,实现RandomAccessFile类使用。 package ch1; import java. io. *; public class ex27 { public static void main(String args[] ) { try { RandomAccessFile in = new in.close ( ); } catch (Exception e) { e.printStackTrace ( ); } } }
A. RandomAccessFileC"ch1/fildat", "read")
B. RandomAccessFile("r", "ch1/fildat")
C. RandomAccessFile("ch1/fildat" , "r")
D. RandomAecessFile("read", "ch1/fildat")
[单项选择]下列程序采用BorderLayout布局管理,选择正确的语句填入横线处,实现在North区域显示一个名字为“北方”的Button构件。 import java.awt.*; public class ex48 { public static void main(String[] args) { frame frm = new Frame ("北方"); frm.setLayout(new BorderLayout( )); frm.setSize(200, 200); frm.setVisible(true); } }
A. add("Nouth", new Button("北方"));
B. fradd("South", new Button("北方"));
C. fradd("Nouth", new Button("北方"));
D. Fradd("South", Button("北方"));
[简答题]接口是抽象方法和常量的集合,是一种特殊的抽象类。下面的程序是对接口的操作,请在程序的每条横线处填写一个语句,使程序的功能完整。
注意:请勿改动main( )主方法和其他已有的语句内容,仅在横线处填入适当的语句。
______________MyInterface
{
public static int NUM=100;
public abstract void print( );
}
public class ClassName___________MyInterface
{
public void print( )
{
System.out.println(NUM);
}
public static void main(String args[])
{
__________________________
obj .print( );
}
}
[单项选择]说明:在每题的语句中有一划横线处,题后有ABCD四个答案,其中只有一个可以放入横线处使语句表达通顺。
如果家长一味地______孩子,那么这个孩子就有可能不能健康成长。
A. 沿着
B. 顺着
C. 依靠
D. 凭着