Win a copy of Grokking Bitcoin this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Frits Walraven
Bartenders:
  • Carey Brown
  • salvin francis
  • Claude Moore

from John Hunt mock-thread suspend and resume  RSS feed

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Q. 55
What is the result of compiling and executing the following Java class:

public class ThreadTest extends Thread {
public void run() {
System.out.println("In run");
suspend();
resume();
System.out.println("Leaving run");
}

public static void main(String args []) {
(new ThreadTest()).start();
}
}

1.Compilation will fail in the method main.
2.Compilation will fail in the method run.
3.A warning will be generated for method run.
4.The string "In run" will be printed to standard out.
5.Both strings will be printed to standard out.
6.Nothing will happen.
Select the most appropriate answer.
1) the answer is 4, why not 5? (looks like the thread is never resumed. why?)
2)will we be tested for those deprecated methods?
Thanks

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
The answer is 4 and not 5 because: after the thread has called the suspend() method, it is not running, so it can't call the resume() method. Another thread has to do that.
I'm really not sure whether we'll be getting questions on deprecated methods in the real exam or not.
Hope that was helpful.
 
Without subsidies, chem-ag food costs four times more than organic. Or this tiny ad:
Create Edit Print & Convert PDF Using Free API with Java
https://coderanch.com/wiki/703735/Create-Convert-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!