[问答题] 下列程序打包到example包,main方法调用线程类输出0~9这10个数,请填写横线处的内容。 注意:请勿改动main()主方法和其他已有语句内容,仅在横线处填入适当语句。 ____

11 查阅

[问答题] 下列程序打包到example包,main方法调用线程类输出0~9这10个数,请填写横线处的内容。

注意:请勿改动main()主方法和其他已有语句内容,仅在横线处填入适当语句。

______

interface MyInterface

public abstract void print(int n);

class Mythread extends Thread ______ MyInterface

public void run()

for(int i = 0; i < 10; i++)

this.print(i);

public void print(int n)

System.out.print(n +" ");

public class Example1_6

public static void main(String argv[])

Mythread th = new Mythread();

______

参考答案:

①package example;②implements③th.start();

MyInterface是自定义的一个接口,Mythread继承于Thread类同时实现了 MyInterface。主方法先根据Mythread生成一个线程,然后将其启动。第1个空,题目中已经说明要将本程序打包到 example包,则说明要使用关键字“package”。第2个空,接口是抽象方法和常量的结合,是一种特殊的抽象类,接口必须通过“implements”实现以后才能被使用。所有线程都通过start()启动,进入线程调度队列。然后,系统会根据一定的算法对线程的运行进行调度,run()方法是线程的线程体。故第3空应该填“th.start()”。

计算机考试