Given:
What change should you make to guarantee a single order of execution (printed values 1 -100 in order)?
Given:
What change should you make to guarantee a single order of execution (printed values 1 -100 in order)?
To ensure a single order of execution where the printed values are in order from 1 to 100, the run() method should be synchronized. By synchronizing the run() method, you prevent multiple threads from accessing it simultaneously and ensure that the increment and print operations occur atomically for each value. This change will guarantee an orderly execution of the values.
Myclass mc = new Thread(mc) has a compilation error
Answer A
Answer is A
A is correct.
Answer is A. Change-> MyClass mc = new MyClass(); Thread a = new Thread(mc); a.start(); Thread b = new Thread(mc); b.start();
I am agreed with you.Answer is A,tested with MyClass mc = new MyClass();
I changed it to MyClass mc = new MyClass(); and compile or even if we try with class MyClass extends Thread or public synchronized run() is still compile.So compiltion error is answer.