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 exam cram Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "exam cram" Watch "exam cram" New topic
Author

exam cram

shabbir zakir
Ranch Hand

Joined: Nov 12, 2000
Posts: 183
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.

What is the answer for this question? Please explain in detail
bill bozeman
Ranch Hand

Joined: Jun 30, 2000
Posts: 1070
A. False - start hasn't been called, all you did was create a new thread.
B. True - Any thread you start will by default have the same priority of the thread that created it. You can change this, but you didn't in your code.
C. True - Since this wasn't created by passing in the class that implements runnable, it will use the run method of the class that has this statement.
D. False - Once a thread stops, it can't be started again.
Bill
Sean Casey
Ranch Hand

Joined: Dec 16, 2000
Posts: 625
I have a question about answer c? Bill, you say it's true, but wouldn't calling the start method only make it eligible to run and it's up to the thread scheduler if it gets run or not. I agree more often than not, it would actually run, but isn't there a chance that it won't?
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
C is false - the construction statement was
Thread myT = new Thread();
which does not attach a Runnable object. Therefore when the run() in Thread is executed, it will be empty. Here is the code in Thread:
public void run() {
if (target != null) { target.run();
}
}
target is of course the Runnable reference, in this case null.
C. the run method in the class where the construction statement appears will be executed.

------------------
author of:
kapil apshankar
Ranch Hand

Joined: Dec 17, 2000
Posts: 66
Hi Bill,
I am still not clear as to why option c is false. Because sooner or later will not the run() method execute? Although the start() method will not directly execute this method, it will nevertheless register the thread making it eligible to run at a later point.
Thanks and regards,
Kapil


Hope this helps. Correct me if I am wrong.<p>Cheers <img src="smile.gif" border="0"> ,<br />Kapil
debasish tripathy
Greenhorn

Joined: Jun 22, 2000
Posts: 8
Thread myT=new Thread();
If myT.start() is called, the run method(which is a do nothing method) of the Thread class will be executed not the run method of the class where the construction statement appears.
If it were
class MyThread extends Thread{
public void run(){
//does something }

public void someFunction(){
Thread myT=new MyThread();
myT.start();} }

then the run method of the class where the construction statement appears will be executed.Because in the above case the run() method of MyThread overrides the run() method of Thread.
Hope this helps
Wong KK
Ranch Hand

Joined: Jan 15, 2001
Posts: 52
This question drops in what construction statement means?
Is construction statement means : new Thread()??
or means the constructor of Thread class??
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: exam cram
 
Similar Threads
q on threads
Thread Question on Exam Cram Mock
ExamCram - Threads
Thread Question
thread question from java cram