• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Threads doubt

Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi ranchers,

Given the code below

public class ThreadDemo extends Thread[
public void run(){
System.out.println("Thread started");
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.

Answer given: B

Yes, i do agree that B will be correct... but only if there is a main method which starts an instance of ThreadDemo by calling start() ...
here should we assume anything and proceed?

going just by the question i would say option D is the correct answer ... am i right in doing so?
If you two don't stop this rough-housing somebody is going to end up crying. Sit down and read this tiny ad:
the value of filler advertising in 2021
    Bookmark Topic Watch Topic
  • New Topic