• 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
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
  • paul wheaton
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Rob Spoor
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:

ExamCram - Threads

 
Ranch Hand
Posts: 270
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have an application that executes the following line:
Thread myT = new Thread() ;
Which statements are correct? [Check all correct answers.]
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.
Answers: B
Why not C also?
Thanks.
 
Ranch Hand
Posts: 808
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Cathy -
It's the run() method of the runnable object that gets called. When you create and start a thread, you either pass it the runnable object or the object creating the thread must be runnable (extend Thread or implement Runnable) and have a run() method that gets called. If these conditions don't exist, Thread.run() is invoked, which does nothing.
From the API for Thread:

If this thread was constructed using a separate Runnable run object, then that Runnable object's run method is called; otherwise, this method does nothing and returns.

 
This tiny ad is suggesting that maybe she should go play in traffic.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic