//What will happen when you attempt to compile and run the following code?
public class TestThread extends Thread {
public static void main(String[] args) {
new TestThread().start();
new TestThread().start();
}
public void run() {
Safe s1 = new Safe("abc");
Safe s2 = new Safe("xyz");
}
}
class Safe {
String str;
public synchronized Safe(String s) {
str = s;
str = str.toUpperCase();
System.out.print(str + " ");
}
}
why does this method public synchronized Safe (String S) give me a compile error ? i know we cant synchronize variable but what is wrong with the above code ?!?!