</p> Q6.You have created a TimeOut class as an extension of Thread, the purpose being to print a “Time's Up” message if the Thread is not interrupted within 10 seconds of being started.' t3 e: L( s4 ~. Y' V: [
Here is the run method which you have coded.
" t8 U" M- R4 a 1. public void run(){6 J/ N$ S5 W* E' T, L6 R
2. System.out.println(“Start!”);3 x2 t6 f$ a& t0 b+ ^4 G2 H
3. try {; ~" k4 m: u, ~+ t; @' V. H
4. Thread.sleep(10000 );
( d, d8 Q- w% z1 q& f 5. System.out.println(“Time's Up!”);
( J9 Q- ~' J1 `! _3 E, S0 O 6. } catch(InterruptedException e) {
9 E8 ^0 u9 e/ ]( @) ~0 F 7. System.out.println(“Interrupted!”);% x8 J* }6 e$ }( @# S
8. }
, P0 V c/ ^5 ?! f- k 9. }, ~ P# [* N0 |- B3 |
Given that a program creates and starts a TimeOut object, which of the following statements is true?, X& P( d& t) I; ]% Y& X
a. Exactly 10 seconds after the start method is called, “Time's Up!” will be printed.' D) { X# @2 N! x
b. Exactly 10 seconds after “Start!” is printed, “Time's Up!” will be printed.
* S5 {7 C8 G) V+ a8 D# x c. The delay between “Start!” being printed and “Time's Up!” will be 10 seconds plus or minus one tick of the system clock.
3 O# X& z) O. F& Y' @& {2 h d. If “Time's Up!” is printed you can be sure at least 10 seconds have elapsed since “Start!” was printed.2 Y) s2 z3 w w) O
4. acd
" O4 ]! P. ~6 x2 O 5. a6 [, j" [& n I: C Z
6. d |