As per my knowledge, the answer c and e are correct!
But not sure whether it is correct.
In the main() method, four threads are started with same Waiting2(Runnable) instance. And the run() method is synchronized so if one
thread gets to execute run() method, others will be blocked.
Lets take 6,7,8,9(as these are only used in the answer) are the ids for the threads created.
The ID of the thread which first gets chance to execute will be printed after incrementing the value of state by 1 and it will start waiting. Like that the next two threads, which will get the chance to execute will print their id after incrementing the value of state by 1 and start waiting.
Till now three ids of different threads are printed.
And when the fourth thread gets chance to execute, if condition which checks the value of state lesser than 3 will become false and else block will get executed. There it will sleep for 2 seconds and notifies the waiting threads. There is no print stmt inside else block so the options d,a,g(which contains 4 diff ids) are eliminated.
The first three waiting threads will execute based on the JVM scheduling. We cannot say in which order they will execute. But the ids of those three threads will be printed.
So the options c and e are correct.
option f is wrong because id 6 is printed thrice.
option b is wrong because ids 7 and 8 will also be printed.
Hope this is clear!