Aê galera… essa é boa
class A extends Thread {
String[] sa;
public A(String[] sa) {this.sa = sa;}
public void run() {
synchronized (sa) {
while (!sa[0].equals("Done")) {
try {sa.wait();} catch (InterruptedException ie) {}
}}
System.out.print(sa[1] + sa[2] + sa[3]);
}}
class B {
private static String[] sa = new String[]{"Not Done","X","Y","Z"};
public static void main (String[] args) {
Thread t1 = new A(sa); t1.start();
synchronized (sa) {
sa[0] = "Done";
sa[1] = "A"; sa[2] = "B"; sa[3] = "C";
sa.notify();
}}}
What is the result of attempting to compile and run the program?
a. Prints: XYZ
b. Prints: AYZ
c. Prints: ABZ
d. Prints: ABC
e. Compile-time error
f. Run-time error
g. None of the above
Abraço