File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Thread Question on Exam Cram Mock

 
wangy
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thought this is an interesting question. I didn't think by choosing C) when I read it.
-------

You have an application that executes the following line: Thread myT = new Thread(); Select all of the following statements that are correct. [Check all correct anwers]
A) The Thread myT is now in a runnable state.
B) The Thread myT has the priority of the Thread that executed the construction statement.
C) If myT.start() is called, the run method in the class where the construction statement appears will be executed.
D) If myT.stop() is called, the Thread can later be started with myT.start() and will execute the run method in the Thread class.

 
Ajith Kallambella
Sheriff
Posts: 5782
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First things first.
Welcome to Javaranch. Your name 'wangy' does not comply with the JavaRanch naming policy. Please choose one that meets the requirements.
Thanks!
 
Ajith Kallambella
Sheriff
Posts: 5782
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's what I think -
A) The Thread myT is now in a runnable state.
Wrong.
myT is a Thread object. It goes to runnable state( Ready to Run ) only when the start() method is called,

B) The Thread myT has the priority of the Thread that executed the construction statement.
Correct - since no priority was specified while creating myT .
C) If myT.start() is called, the run method in the class where the construction statement appears will be executed.
Wrong.
myT is a Thread object, not an object of a class that extends Thread. When you call myT.start() the run() method defined in the Thread class gets executed which does nothing.
D) If myT.stop() is called, the Thread can later be started with myT.start() and will execute the run method in the Thread class.
Wrong.
You cannot start() a thread that has been stopped. When you call stop() on a thread, if the thread is running, it gets stopped abnormally. There is no way to restart it using the same thread object.
Hope that helps!

------------------
Ajith Kallambella M.
Sun Certified Programmer for the Java�2 Platform.
IBM Certified Developer - XML and Related Technologies, V1.
 
kriti sharma
Ranch Hand
Posts: 160
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi wangy,
the only answer i found correct is b. not even c because run method if not defined in the class which creates the thread may still be executed from the Thread class.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic