✅ The verified answer to this question is available below. Our community-reviewed solutions help you understand the material better.
public abstract class SomeClass implements Runnable {
public static Object lock = new Object ();
public void lock () {
synchronized (lock) {
try {
lock.wait ();
System.out.print ( "1");
} Catch (InterruptedException e) { }
}
}
public void notifyThread () {
synchronized (lock) {
lock.notify ();
}
}
public void unlock () {
synchronized (lock) {
lock.notify ();
System.out.print ( "2");
}
}
public static void main (String s []) {
final SomeClass c = new SomeClass () {
public void run () {
lock ();
notifyThread ();
}
};
final SomeClass c1 = new SomeClass () {
public void run () {
unlock ();
}
};
new Thread (c) .start ();
new Thread (c1) .start ();
}
}
(Java)