voidwaitForSignal(){Objectobj=newObject();synchronized(Thread.currentThread()){obj.wait();obj.notify();}}Whichistrue?()A.ThiscodemaythrowanInterruptedException.B.ThiscodemaythrowanIllegalStateException.C.ThiscodemaythrowaTimeoutExceptionaftertenminutes.D.

题目
voidwaitForSignal(){Objectobj=newObject();synchronized(Thread.currentThread()){obj.wait();obj.notify();}}Whichistrue?()

A.ThiscodemaythrowanInterruptedException.

B.ThiscodemaythrowanIllegalStateException.

C.ThiscodemaythrowaTimeoutExceptionaftertenminutes.

D.Thiscodewillnotcompileunless“obj.wait()”isreplacedwith“((Thread)obj).wait()”.

E.Reversingtheorderofobj.wait()andobj.notify()maycausethismethodtocompletenormally.

F.Acalltonotify()ornotifyAll()fromanotherthreadmaycausethismethodtocompletenormally.


相似考题
参考答案和解析
参考答案:B
更多“voidwaitForSignal(){Objectobj=newObject();synchronized(Thread.currentThread()){obj.wait();obj.notify();}}Whichistrue?() ”相关问题
  • 第1题:

    publicclassTwoThreads{

    privatestaticObjectresource=newObject();

    privatestaticvoiddelay(longn){

    try{Thread.sleep(n);}

    catch(Exceptione){System.out.print(”Error);}

    }

    publicstaticvoidmain(String[]args){

    System.out.print(”StartMain);

    newThread1().start();

    delay(1000);

    Threadt2=newThread2();

    t2.start();

    delay(1000);

    t2.interrupt

    delay(1000);

    System.out.print(”EndMain);

    }

    staticclassThread1extendsThread{

    publicvoidrun(){

    synchronized(resource){

    System.out.print(”Startl);

    delay(6000);

    System.out.print(”End1);

    }

    }

    }

    staticclassThread2extendsThread{

    publicvoidrun(){

    synchronized(resource){

    System.out.print(”Start2);

    delay(2000);

    System.out.print(”End2);

    }

    }

    }

    }

    Assumethatsleep(n)executesinexactlymmilliseconds,andallothercodeexecutesinaninsignificantamountoftime.Whatistheoutputifthemain()methodisrun?()


    参考答案:F

  • 第2题:

    把一个对象写到一个流中相对比较简单,具体是通过调用ObjectOutputStream类的writeObject()方法实现的,那么该方法的定义为( )。

    A.public final int writeObject(Object obj) throws IOException

    B.public final void writeObject(Object obj) throws IOException

    C.public Object writeObject(Object obj) throws IOException

    D.public final Object writeObject(Object obj) throws IOException


    正确答案:B
    解析:writeObject()方法的正确定义为: public final void writeObject(Object Obj) throws IOException。即B选项的定义是正确的。

  • 第3题:

    newObject为body对象的一级子节点,newObject.css("display","block");将使得newObject可见。


    错误

  • 第4题:

    publicstaticvoidmain(String[]args){12.Objectobj=newObject(){13.publicinthashCode(){14.returns42;15.}16.};17.System.out.println(obj.hashCode());18.}Whatistheresult?()

    A.42

    B.Anexceptionisthrownatruntime.

    C.Compilationfailsbecauseofanerroronline12.

    D.Compilationfailsbecauseofanerroronline16.

    E.Compilationfailsbecauseofanerroronline17.


    参考答案:A

  • 第5题:

    设有如下代码:

    interface IFace{}

    class CFace implements IFace{}

    class Base{}

    public class ObRef extends Base{

    public static void main(String argv[]){

    ObRef bj = new ObRef();

    Base b = new Base();

    Object obj1 = new Object();

    IFace obj2 = new CFace();

    //Here

    }

    }

    则在 //Here处插入哪个代码将不出现编译和运行错误。

    A.obj1=obj2;

    B.b=obj;

    C.obj=b;

    D.obj1=b;


    正确答案:ABD