Given:
public class SleepOtherThread {
public static void main(String[] args) throws InterruptedException {
Runnable r = new Runnable() {
public void run() {
System.out.print(Thread.currentThread().getName());
}
};
Thread t1 = new Thread(r, “One “);
t1.start();
t1.sleep(2000);
Thread t2 = new Thread(r, “Two “);
t2.start();
t2.sleep(1000);
System.out.print(“Main “);
}
}
What is the most likely result?
A.
Main One Two
B.
Main Two One
C.
One Two Main
D.
One Main Two
E.
Two Main One
sleep() is a static method of Thread class to sleep the current executing thread, so t1.sleep() is identical to Thread.sleep(), to sleep the main thread.
Thanks for the explanation.
C is the correct answer.
+1 Tested
C
C