• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

Thread Question on Exam Cram Mock

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
These are the worst of times and these are the best of times. And this is the best tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic