下列程序打包到example包,main方法调用线程类输出0~9这10个数,请填写横线处的内容。 注意:请勿改

12 查阅

下列程序打包到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();①package example;②implements③th.start(); 解析:MyInterface是自定义的一个接口,Mythread继承于Thread类同时实现了 MyInterface。主方法先根据Mythread生成一个线程,然后将其启动。第1个空,题目中已经说明要将本程序打包到 example包,则说明要使用关键字“package”。第2个空,接口是抽象方法和常量的结合,是一种特殊的抽象类,接口必须通过“i

计算机二级