Java Reference
In-Depth Information
15. public static void main(String [] args) {
16. Runnable x = new PrintSomething(“x”);
17. Runnable y = new PrintSomething(“y”);
18. Thread one = new Thread(x);
19. Thread two = new Thread(y);
20. two.start();
21. one.start();
22. }
23. }
A. The output is always xy.
B. The output is always yx.
C. The output can be either xy or yx.
D. Lines 16 and 17 generate compiler errors.
E. Lines 18 and 19 generate compiler errors.
5. Given the following MyTarget class definition:
1. public class MyTarget {
2. public void run() {
3. for(int i = 1; i <= 10; i++) {
4. System.out.print(“x”);
5. }
6. }
7. }
what is result of the following program?
1. public class PrintX {
2. public static void main(String [] args) {
3. MyTarget target = new MyTarget();
4. Thread t = new Thread(target);
5. t.start();
6. System.out.print(“y”);
7. }
8. }
A. xxxxxxxxxxy
B. yxxxxxxxxxx
C. Ten xs and one y printed in an indeterminate order.
D. xxxxxxxxxxy or yxxxxxxxxxx
E. The code does not compile.
Search WWH ::




Custom Search