• 下列程序打包到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
  • 2021年07月15日 22时24分来自  问答库 >> 计算机类
  • 评论 0
  • 手机玩微博

    手机版 手机端
    Powered by 日新微博 © 2018 - 2020 日新网