Question 18.
Given the code below
public class ThreadDemo extends
Thread[
public void run(){
System.out.println("Thread started");
try{
Thread.sleep(20000); //20 seconds sleep
System.out.println("I am Back from my sleep");
}
catch(InterruptedException e){
System.out.println("I got Interrupted");
}
}
}
Which of the following statements are true?
A.Exactly 20 seconds after the start method
is called "I am Back from my sleep" be printed.
B.We can be sure that atleast after 20 seconds elapsed,
"I am Back from sleep" will be printed.
C.The delay between output "Thread started" and "I am Back
from sleep" is less or more than 20 seconds.
D.None of the above.
//I CHOSE D, SINCE THERE IS NO start() method invocation, how can run() be invoked ??
Given the following code segments, select the ones that are legal.
A.boolean b = true;
int i = 10;
String s = b + i;
B.char c = 10;
int i = 20;
c += i;
C.String s = "Hello" ;
int i = 10;
i += s;
D.boolean b = null ;
if( b == null ){};
E.String s = "Hello" ;
int i = 10;
s += i;
F.Integer ii = new Integer(10);
int i = 10;
ii += i;
//I CHOSE E BUT ANSWER LIKES B AS WELL, HOW ??