下列程序打包到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

题目

下列程序打包到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();

______

}

}


相似考题
更多“下列程序打包到example包,main方法调用线程类输出0~9这10个数,请填写横线处的内容。 注意:请勿改 ”相关问题
  • 第1题:

    创建线程对象,要传递代码与数据,而传递代码与数据有两种方法,一是通过继承Thread类,二是向Thread类传递一个Runnable对象。请在下面程序的每条横线处填写一个语句,使程序的功能完整。

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

    public class TestThread{

    public static void main(String args[ ])

    {

    MyThread t=new MyThread();

    _______________________

    }

    }

    class MyThread_____________Thread{

    _____________________

    {

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

    System.out.println(" " +i);

    }

    }

    }


    正确答案:t.start(); extends public void run();
    t.start(); extends public void run(); 解析: 本题主要考查创建线程的方法、线程的执行过程。解答本题的关键是熟练掌握创建线程的方法、执行过程。在本题中, t.start();语句的功能是启动线程t,使其处于可运行状态,classMyThreadextendsThread中的extends的作用是使Mythread线程为线程Thread的直接子类,public void run()的功能是重载run()方法。

  • 第2题:

    下面的程序的功能是简单的进行键盘输入测试,请在程序的每条横线处填写一个语句,使程序的功能完整。

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

    ____________________

    public class TestKeyBoardInPut

    {public static void main(String[] args)

    {String yourname=JOptionPane. ____________________ ("What is your name?");

    System.out.println("Hello"+yourname);

    ____________________.exit(0);

    }

    }


    正确答案:import javax.swing.*; showInputDialog System
    import javax.swing.*; showInputDialog System 解析:本题主要考查javax.swing包、showInputDialog()方法。解答的关键是掌握javax.swing包、showInputDialog()方法。在本题中,import javax.swing.*;语句的功能是导入javax.swing包,String yourname=JOptionPane.showInputDialog("What is your name?");语句的功能是从控制台键盘读入字符串并赋值yourname,System.exit(0);语句的功能是退出Java的运行环境回到操作系统环境下。

  • 第3题:

    下面的程序是打印输出100~300之间的不能被3整除的数。请在每条横线处填写一条语句,使程序的功能完整。

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

    public class printNo3and5{

    void print()

    {

    int n ;

    for(n=100 ;n<=300 ;n++){

    if(n%3==0)

    __________

    System.out.println(n);

    }

    }

    public static__________main(String args[])

    {

    printNo3and5 bj=new printN03and5();

    __________

    }

    }


    正确答案:continue; void obj.print();
    continue; void obj.print();

  • 第4题:

    下面程序是关于类的继承的用法。阅读下面程序,根据程序中的注释在每一条横线处填写一个语句,使程序的功能完整,且运行程序后的输出结果为:

    I am parentclass!

    I am childclass!

    I am childclass!

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

    class Parent {

    void printMe() {

    System.out.println("I am parentclass!");

    }

    }

    class Child extends Parent {

    void printMe() {

    System.out.println("I am childclass!");

    }

    void printAll() {

    ______________.printMe ( ); // 调用父类的方法

    ______________. printMe ( ); //调用本类的方法

    printMe ( );

    }

    }

    public class TestJieCheng {

    public static void main(String args[]) {

    ______________

    myC.printAll();

    }

    }


    正确答案:super this Child myC=new Child();
    super this Child myC=new Child(); 解析:本题主要考查super,this关键字以及如何生成对象。解答本题的关键是熟练super,this的用法、对象的生成。在本题中, super.printMe();语句的功能是调用父类的printMe()方法,this.printMe();语句的功能是调用本类的printMe()方法,Child myC=new Child();语句的功能是生成Child类的对象myC。

  • 第5题:

    下面的程序是用do_while语句计算10的阶乘。请在程序的每条横线处填写一个语句,使程序的功能完整。

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

    源程序文件代码清单如下:

    public class DoWhileLoop

    {

    public static void main(________)

    {

    int n=10;

    long result=1;

    do

    {

    _______________

    }

    ______________

    System.out.println("10的阶乘为: "+result);

    }

    }


    正确答案:String args[] result*=n--; while(n>=1);
    String args[] result*=n--; while(n>=1); 解析:本题主要考查main()主方法的使用、while循环语句的用法。解答本题的关键是熟练掌握 main()土方法的使用、while循环语句的用法。在本题中,String args[]的作用是声明字符数组args, result*=n--;语句的作用是获得n的阶乘并赋值给变量result。