File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Thread Question on Exam Cram Mock Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Thread Question on Exam Cram Mock" Watch "Thread Question on Exam Cram Mock" New topic
Author

Thread Question on Exam Cram Mock

wangy
Greenhorn

Joined: Apr 05, 2001
Posts: 1
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

Joined: Mar 17, 2000
Posts: 5782
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!

Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
Ajith Kallambella
Sheriff

Joined: Mar 17, 2000
Posts: 5782
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

Joined: Feb 16, 2001
Posts: 160
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Thread Question on Exam Cram Mock