首页 > 试题广场 >

下面2个类, 你想在第二个类里面启动第一个类的线程,在第15

[单选题]
下面2个类, 你想在第二个类里面启动第一个类的线程,在第15行应该怎样做?(  )
1 public class Century implements Runnable {
2 public void run () {
3 for (int year = 1900;year < 2000;year++) {
4 System.out.println(year);
5 try {Thread.sleep(1000);
6 } catch(InterruptedException e) {}
7 }
8 System.out.println("Happy new millenium!");
9 }
10 }
11
12 class CountUp {
13 public static void main (String [] args) {
14 Century ourCentury = new Century();
15
16 }
17 } 

  • Thread t = new Thread(this);
    t.start();
  • Thread t = new Thread(this);
    t.start(ourCentury);
  • Thread t = new Thread(this);
    ourCentury.run();
  • Thread t = new Thread(ourCentury);
    t.start();

this:当前对象

发表于 2020-08-04 14:35:52 回复(2)