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.

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.


相关考题:

Whichthreewillcompileandrunwithoutexception?() A.privatesynchronizedObjecto;B.voidgo(){synchronized(){/*codehere*/}C.publicsynchronizedvoidgo(){/*codehere*/}D.privatesynchronized(this)voidgo(){/*codehere*/}E.voidgo(){synchronized(Object.class){/*codehere*/}F.voidgo(){Objecto=newObject();synchronized(o){/*codehere*/}

1.public class GC{2.private Objec to;3.private void doSomethingElse(Object obj){o=obj;}4.public void doSomething(){5.Object o=new Object();6.doSomethingElse(o);7.o=new Object();8.doSomethingElse(null);9.o=null;10.}11.}When the doSomething method is called,after which line does the Object created in line 5 become available for garbage collection?()A.Line5B.Line6C.Line7D.Line8E.Line9F.Line10

publicclassTestSevenextendsThread{privatestaticintx;publicsynchronizedvoiddoThings(){intcurrent=x;current++;x=current;}publicvoidrun(){doThings();}}Whichistrue?() A.Compilationfails.B.Anexceptionisthrownatruntime.C.Synchronizingtherun()methodwouldmaketheclassthread-safe.D.Thedatainvariable“x”areprotectedfromconcurrentaccessproblems.E.DeclaringthedoThings()methodasstaticwouldmaketheclassthread-safe.F.WrappingthestatementswithindoThings()inasynchronized(newObject()){}blockwouldmaketheclassthread-safe.

Whichthreewillcompileandrimwithoutexception?() A.privatesynchronizedObjecto;B.voidgo(){synchronized(){/*codehere*/}}C.publicsynchronizedvoidgo(){/*codehere*/}D.privatesynchronized(this)voidgo(){/*codehere*/}E.voidgo(){synchronized(Object.class){/*codehere*/}}F.voidgo(){Objecto=newObject();synchronized(o){/*codehere*/}}

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.interruptdelay(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?()

publicstaticvoidmain(String[]args){12.Objectobj=newObject(){13.publicinthashCode(){14.returns42;15.}16.};17.System.out.println(obj.hashCode());18.}Whatistheresult?() A.42B.Anexceptionisthrownatruntime.C.Compilationfailsbecauseofanerroronline12.D.Compilationfailsbecauseofanerroronline16.E.Compilationfailsbecauseofanerroronline17.

把一个对象写到一个流中相对比较简单,具体是通过调用ObjectOutputStream类的writeObject()方法实现的,那么该方法的定义为( )。A.public final int writeObject(Object obj) throws IOExceptionB.public final void writeObject(Object obj) throws IOExceptionC.public Object writeObject(Object obj) throws IOExceptionD.public final Object writeObject(Object obj) throws IOException

设有如下代码: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;

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