题目内容

对于下列程序,哪个叙述是正确的?()public class E {public static void main(String args[]) {Target target =new Target();Thread thread =new Thread(target);thread.start();}}class Target implements Runnable{public void run(){System.out.println("ok");}}

A. JVM认为这个应用程序共有两个线程。
B. JVM认为这个应用程序只有一个主线程。
C. JVM认为这个应用程序只有一个thread线程。
D. thread的优先级是10级。

查看答案
更多问题

在多线程程序设计中,如果采用继承Thread类的方式创建线程,则需要重写Thread类的()方法。

A. start
B. do
C. interrupt
D. run

运行下列程序,产生的结果是 ()。public class Example12_1 extends Thread implements Runnable{public void run(){System.out.println("this is run()");}public static void main(String args[]){Thread t=new Thread(new Example12_1();t.start();}}

A. 第一行会产生编译错误
B. 第六行会产生编译错误
C. 第六行会产生运行错误
D. 程序会运行和启动

在下列E类中【代码】输出结果是_____.import java.awt.*;import java.awt.event.*;public class E implements Runnable {StringBuffer buffer=new StringBuffer();Thread t1,t2;E() { t1=new Thread(this);t2=new Thread(this);}public synchronized void addChar(char c) {if(Thread.currentThread()==t1) {while(buffer.length()==0) {try{ wait();}catch(Exception e){}}buffer.append(c);}if(Thread.currentThread()==t2) {buffer.append(c);notifyAll();}}public static void main(String s[]) {E hello=new E();hello.t1.start();hello.t2.start();while(hello.t1.isAlive()||hello.t2.isAlive()){}System.out.println(hello.buffer); //【代码】}public void run() {if(Thread.currentThread()==t1)addChar('A') ;if(Thread.currentThread()==t2)addChar('B') ;}}

A. BA
B. A
C. B
D. AB

下面属于Java线程同步方法的方法有()。

A. join()
B. run()
C. wait()
D. destroy()

答案查题题库