Vous êtes sur la page 1sur 7

3.

Which of the following will not directly cause a thread to stop? A. notify() B. wait()

C.

InputStream access

sleep()

!3. Which two cause a compiler error? !. &. 3. '. (. float" # f $ new float(3)% float f&" # $ new float" #% float" #f! $ new float"3#% float f3" # $ new float"3#% float f(" # $ )!.*f+ &.*f+ &.*f,% A. &+ ' B. 3+ (

C.

'+ (

!+ &

!(. public class Test { } What is the prototype of the default constructor? A. -est( ) B. -est(.oid)

C.

pu/lic -est( )

pu/lic -est(.oid)

!0. Which two can /e used to create a new -hread?

1. 12tend java.lang.Thread and o.erride the run() method. 2. 12tend java.lang.Runnable and o.erride the start() method. 3. Implement java.lang.Thread and implement the run() method. 4. Implement java.lang.Runnable and implement the run() method. 5. Implement java.lang.Thread and implement the start() method.
A. ! and & B. & and 3

C.

! and '

3 and '

!*. class X implements Runnable { public static void main(String args[]) { /* Missing code? */ } public void run() {} } Which of the following line of code is suita/le to start a thread ? A. -hread t $ new -hread(3)%

B.

-hread t $ new -hread(3)% t.start()%

C.

3 run $ new 3()% -hread t $ new -hread(run)% t.start()%

-hread t $ new -hread()% 2.run()%

!3. What will /e the output of the program? class s implements Runnable { int x, y; public void run() { for(int i 0; i ! 1000; i"") synchronized(this) { x 12; y 12; } System.#ut.$rint(x " " " " y " " "); } public static void main(String args[]) { s run new s(); Thread t% new Thread(run);

Thread t& new Thread(run); t%.start(); t&.start(); } } ead4oc5 It print !& !& !& !&

A.

B.

C.

Compilation 1rror

Cannot determine output.

!'. public class Test { public void '##() { assert false; /* Line 5 */ assert false; /* Line 6 */ } public void bar() { while(true) { assert false; /* Line 12 */ } assert false; /* Line 14 */ } } What causes compilation to fail? A. 4ine (

B.

4ine 6

C.

4ine !&

4ine !'

'. /* Missing statements ? */ public class NewTreeSet extends java.util.TreeSet

{ public static void main(String [] args) { java.util.TreeSet t new java.util.TreeSet(); t.(lear(); } public void (lear() { Tree)a$ m new Tree)a$(); m.(lear(); } } which two statements+ added independently at /eginning of the program+ allow the code to compile? !. 7o statement is re8uired

&. im$#rt java.util.*; +. im$#rt.java.util.Tree*; ,. im$#rt java.util.TreeSet; -. im$#rt java.util.Tree)a$;


A. ! only B. & and (

C.

3 and '

3 and (

!*. Which class does not o.erride the e.uals() and hash/#de() methods+ inheriting them directly from class 9/:ect? A. :a.a.lang.String B. :a.a.lang. ou/le

C.

:a.a.lang.StringBuffer

:a.a.lang.Character

!!. ;ou need to store elements in a collection that guarantees that no duplicates are stored and all elements can /e accessed in natural order. Which interface pro.ides that capa/ility? A. :a.a.util.<ap B. :a.a.util.Set

C.

:a.a.util.4ist

:a.a.util.Collection

!'. public class MyOuter { public static class MyInner { public static void '##() { } } } which statement+ if placed in a class other than )y0uter or )y1nner+ instantiates an instance of the nested class? A. <y9uter.<yInner m $ new <y9uter.<yInner()%

B.

<y9uter.<yInner mi $ new <yInner()%

<y9uter m $ new <y9uter()% C. <y9uter.<yInner mi $ m.new <y9uter.<yInner()%

<yInner mi $ new <y9uter.<yInner()%

!(. Which two are .alid constructors for -hread? !. &. 3. '. (. -hread(=unna/le r+ String name) -hread() -hread(int priority) -hread(=unna/le r+ -hread>roup g) -hread(=unna/le r+ int priority) A. ! and 3 B. & and '

C.

! and &

& and (

Wor5space

!6. Which two of the following methods are defined in class -hread? !. &. 3. start() wait() notify()

'. (.

run() terminate() A. ! and ' B. & and 3

C.

3 and '

& and '

!?. @nder which conditions will a currently e2ecuting thread stop? !. &. 3. When an interrupted e2ception occurs. When a thread of higher priority is ready (/ecomes runna/le). When the thread creates a new thread.

4. When the st#$() method is called.


A. ! and 3 B. & and '

C.

! and '

& and 3

!(. What will /e the output of the program? TreeSet ma$ new TreeSet(); ma$.add("one"); ma$.add("two"); ma$.add("three"); ma$.add("four"); ma$.add("one"); 1terat#r it ma$.iterat#r(); while (it.has2ext() ) { System.#ut.$rint( it.next() " " " ); } A. one two three four

B.

four three two one

C.

four one three two

one two three four one

Vous aimerez peut-être aussi