Java Reference
In-Depth Information
C. else
D. Do something
E. The output is indeterminate.
3. Given the following PrintA class definition:
1. public class PrintA extends Thread {
2. public void run() {
3. System.out.print(“A”);
4. }
5. }
which of the statements is true about the following PrintB program? (Select one.)
1. public class PrintB {
2. public static void main(String [] args) {
3. Thread a = new PrintA();
4. a.run();
5.
6. System.out.print(“B”);
7. }
8. }
A. The program generates an exception at runtime.
B. The program does not compile.
C. The output varies and is either AB or BA.
D. The output is always AB.
4. Which of these statements is true about the following PrintSomething program?
(Select one.)
1. public class PrintSomething implements Runnable {
2. private String value;
3.
4. public PrintSomething(String value) {
5. this.value = value;
6. }
7.
8. public void run() {
9. try {
10. Thread.sleep((int) (Math.random() * 4000));
11. }catch(InterruptedException e) {}
12. System.out.print(value);
13. }
14.
Search WWH ::




Custom Search