1. class A implements runable ( 2. int i; 3. public void run () ( 4. try ( 5. thread.sleep(5000); 6. i= 10; 7. ) catch(InterruptedException e) {} 8. ) 9. ) 10. 11. public class Test { 12. public static void main (string args) ( 13. try ( 14. A a = new A (); 15. Thread t = new Thread (a); 16. t.start(); 17. 18. int j= a.i; 19. 20. ) catch (Exception e) {} 21. ) 22. ) Which statement al line 17 will ensure that j=10 at line 19?()
A、 a.wait();
B、 t.wait();
C、 t.join();
D、 t.yield();
E、 t.notify();
F、 a.notify();
G、 t.interrupt();
相关问题推荐
-
Which two are true about has-a and is-a relationships?()
AInheritance represents an is-a relationship.
BInheritance represents a has-a relationship.
CInterfaces must be used when creating a has-a relationship.
DInstance variables can be used when creating a has-a relationship.
-
public class Foo implements Runnable ( public void run (Thread t) { system.out.printIn(“Running.”); } public static void main (String[] args) { new thread (new Foo()).start(); } ) What is the result?()
A、 An exception is thrown.
B、 The program exists without printing anything.
C、 An error at line 1 causes compilation to fail.
D、 An error at line 2 causes the compilation to fail.
E、 “Running” is printed and the program exits.
-
Which two code fragments represent these relationships?()
Aclass Widget{Sprocket s;};class Gadget extends Widget{Spring s;}
Bclass Widget{};class Gadget extends Widget{Spring s1; Sprocket s2;}
Cclass Widget{Sprocket s1; Spring s2;};class Gadget extends Widget{}
Dclass Gadget{Spring s;};class Widget extends Gadget{Sprocket s;}
Eclass Gadget{};class Widget extends Gadget{Sprocket s1; Spring s2;}
Fclass Gadget{Spring s1; Sprocket s2;};class Widget extends Gadget{}
-
1. import java.util.*; 2. public class Test { 3. public static void main(String[] args) { 4. List strings = new ArrayList(); 5. // insert code here 6. } 7. } Which four, inserted at line 5, will allow compilation to succeed?()
AString s = strings.get(0);
BIterator i1 = strings.iterator();
CString[] array1 = strings.toArray();
DIterator i2 = strings.iterator();
EString[] array2 = strings.toArray(new String[1]);
FIterator i3 = strings.iterator();
-
package geometry; public class Hypotenuse { public InnerTriangle it = new InnerTriangle(); class InnerTriangle { public int base; public int height; } } Which is true about the class of an object that can reference the variable base? ()
A、 It can be any class.
B、 No class has access to base.
C、 The class must belong to the geometry package.
D、 The class must be a subclass of the class Hypotenuse.