Java Reference
In-Depth Information
D. The getBalance method can be invoked even if the object's monitor is owned by
another thread.
E. Line 9 generates a compiler error.
10. Given the following Paint class definition, which of the following statements is true?
(Select one.)
1. public class Paint {
2. private static int color = 1;
3.
4. public synchronized static void setColor(
5. int newColor) {
6. color = newColor;
7. }
8.
9. public synchronized static int getColor() {
10. return color;
11. }
12. }
A. The color field is protected from concurrent access problems.
B. Line 2 generates a compiler error.
C. Lines 4 and 9 generate compiler errors.
D. Lines 6 and 10 generate compiler errors.
11. Given the following MyConsumer class definition:
1. public class MyConsumer extends Thread {
2. private StringBuffer sb;
3.
4. public MyConsumer(StringBuffer sb) {
5. this.sb = sb;
6. }
7. public void run() {
8. if(sb != null && sb.length() == 0) {
9. try {
10. System.out.println(“Waiting”);
11. sb.wait();
12. }catch(InterruptedException e) {}
13. }
14. sb.reverse();
15. }
16. }
Search WWH ::




Custom Search