Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

valiveru exam errata - please confirm REAL answers, thanks!

 
sarim raza
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ??
 
vadiraj vd
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For your first question I think the answer B is correct.
Here you are creating your own thread extending Thread class. You are going to create an object on this class(ThreadDemo) and call start() method.
Regarding my answer, the thread goes to sleep for atleast the specified interval. When it comes back there is a chance that a higher priority thread is running and this thread is put into the ready queue. So we can be sure that the thread sleeps for atleast the specified interval.
-----------

For your second question, the extended assignment operators have the cast built-in. so,
1. char c = 10;
2. int i = 20;
3. c += i;
is valid. At line 3, the += operator will do a implicit conversion from int to char and assigns the value to c.
Hope this helps.
regards
vadiraj
------------
 
sarim raza
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks a lot, that was so helpful !
appreciate it!
 
sunilkumar ssuparasmul
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
for the second case
the type casting is done bcos char is unsigned so the range of char is lies within int since it is signed so implicit type casting is done.
thanks,
sunil.s
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic