Win a copy of Bad Programming Practices 101 (e-book) this week in the Beginning Java forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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.
 
What could go wrong in a swell place like "The Evil Eye"? Or with this tiny ad?
Why should you try IntelliJ IDEA ?
https://coderanch.com/wiki/696337/IntelliJ-IDEA
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!