class A9o extends
Thread {
String[] sa;
public A9o(String[] sa) {this.sa = sa;}
public void run()
{
synchronized (sa)
{
System.out.print(sa[0] + sa[1] + sa[2]);
}
}
}
class TestCalss5
{
private static String[] sa = new String[]{"X","Y","Z"};
public static void main (String[] args)
{
synchronized (sa)
{
A9o t1 = new A9o(sa); t1.start();
try{t1.join(900);} catch(InterruptedException e){}
sa[0] = "A"; sa[1] = "B"; sa[2] = "C";
}
}
}
In the above code, when the either of the synchronized statements are removed then the output is "XYZ" orelse "ABC".
Please explain.
Thanks in advance
Kayal