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

 
Daniel Liu
Greenhorn
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Question: [Check all the correct answers]
You have an application which execute the following line:
Thread myT = new Tread();
myT.start();

Select all of the crrect statements.
a. The Tread myT is now in a runnable state.
b. The Tread myT has the NORM_PRIORITY priority.
c. The Tread myT will die without accomplishing anthing.
d. The run method in the class where the statement occurs will be executed.
The answers are a and b. But why not b and d?
 
Daniel Liu
Greenhorn
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, there was a typo in my original post so I it repost below.
You have an application which execute the following line:
Thread myT = new Tread();
myT.start();

Select all of the crrect statements.
a. The Tread myT is now in a runnable state.
b. The Tread myT has the NORM_PRIORITY priority.
c. The Tread myT will die without accomplishing anthing.
d. The run method in the class where the statement occurs will be executed.
The answers are a and c. But why not b and d? [/B]
 
Ajith Kallambella
Sheriff
Posts: 5782
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Daniel,
What you are doing is creating an instance of the Thread class, not of any of its' subclasses. Remember the run() method defined in the Thread class doesn't do anything? That's why the thread that you starts dies without accomplishing anything.
Usually we extend the Thread class or implement Runnable to provide our own implementation of the run() method. Then we create a thread from our class. But this question is perfectly valid and attempts to validate your knowledge about threads.
Beware of such questions in the exam!!
Ajith
 
Aru
Ranch Hand
Posts: 112
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ajith,
So which answers are the right ones for the question. Can you be a little more specific.
Thanks
Aruna
 
Daniel
Greenhorn
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I think choice b is crrect too because the default priority value is NORM_PRIORITY
 
Ajith Kallambella
Sheriff
Posts: 5782
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the correct answers are (a) and (c).
Daniel, I don't think the answer (b) is right. When a thread is created, it "inherits" the priority of the parent thread. Eventhough the default priority is NORM_PRIORITY, we cannot assume anything about the thread which executes the given code.
Ajith
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic