File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Valid Statement

 
Alk
Greenhorn
Posts: 25
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which of the following statements is valid?
A.The JVM runs till the main method exits, even if there are other user threads running.
B.An InterruptedException occurs when the sleep() method is called on a thread.
C.A thread can be suspended for an indefinite duration of time.
D.A thread can be made in Java only by subclassing the Thread class.
E.The synchronize keyword can be used only in a method that is part of a class that is derived from Thread.
I think the correct answers are B) and c)
Any Suggestions?
Alk
 
Sridhar Garimella
Ranch Hand
Posts: 73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which of the following statements is valid?
A.The JVM runs till the main method exits, even if there are other user threads running.
B.An InterruptedException occurs when the sleep() method is called on a thread.
C.A thread can be suspended for an indefinite duration of time.
D.A thread can be made in Java only by subclassing the Thread class.
E.The synchronize keyword can be used only in a method that is part of a class that is derived from Thread.
I think the correct answers are B) and c)
Any Suggestions?
Alk

I think u are right.D and E are wrong because thread can be created either extends Thread or implements Runnable.A is also wrong because jvm runs even if the main thread terminates and other threads still there.This case occurs if main thread has low priority and other user threads have high priority.
 
Anonymous
Ranch Hand
Posts: 18944
  • 0
  • send pies
  • Quote
  • Report post to moderator
I think, InterruptedException will not occur when sleep() is called on a thread, but the thread will be moved from running state to sleeping state. While sleeping, it can get that exception.
 
Lucy C
Ranch Hand
Posts: 53
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, B is definitely wrong - an InterruptedException is thrown when interrupt() is called on a thread. A sleeping thread can throw this exception if it is interrupted by another thread - hence the fact that sleep() throws InterruptedException.
 
josephine chen
Ranch Hand
Posts: 216
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

A.The JVM runs till the main method exits, even if there are other user threads running.//f
The Java Virtual Machine continues to execute threads until --All threads that are not daemon threads(means user threads) have died, either by returning from the call to the run method or by throwing an exception that propagates beyond the run method.
B.An InterruptedException occurs when the sleep() method is called on a thread.
Throws:InterruptedException - if another thread has interrupted the current thread.

C.A thread can be suspended for an indefinite duration of time.
//f
D.A thread can be made in Java only by subclassing the Thread class. //f
E.The synchronize keyword can be used only in a method that is part of a class that is derived from Thread. //f
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic