【说明】
下面的程序的功能是利用实现Runnable接口的方法来创建线程,并利用它来执行响应的一些操作。最后使得m的执行结果:100,如图3。
注意:请勿改动main()主方法和其他已有的语句内容,仅在下划线处填入适当的语句。
class ClassName (1) Runnable
int n;
(2)
try
Thread. sleep (2000);
n=100;
catch( (3) e)
public static void main(String[ ]args)
try
ClassName a = new ClassName( );
(4)
threadl. (5) ();
threadl, join( );
int m=a.n;
System. out. println("m=" + m);
catch( (3) e)
参考答案:(1)implements (2)ClassName (3)Exception
(4)ClassName threadl=new ClassName(); (5)start
解析: 此处为实现接口关键字。
此处应填类ClassName的构造函数名,即ClassName。此处应填异常类名Exception。定义并初始化刘象threadl。线程的启动函数。