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

Another question from Khalid

 
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yesterday I was throwing some questions for Khalid's mock exam out here because I found that mock to be the most difficult mock exam out there. I have been going through the mock a question at a time making sure I understand every point fully. In going with that, I thought I would throw some questions out here.
You can do a search for Khalid and posts by me (bill bozeman) to see some of the other questions and discussions.
Here is another one:

9. Given that a static method doIt() in a class Work represents work to be done, what block of code will succeed in starting a new thread that will do the work?

Select all valid answers:
A. Code block A
B. Code block B
C. Code block C
D. Code block D
E. Code block E

Again, try to figure out the answer, then try to compile it and run it to see what you get.
Hope these help some, I know they helped me.
Bill
[This message has been edited by bill bozeman (edited December 21, 2000).]
 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bill,
When i answered the test i gave the option as A. But when i complied and saw the code it is giving me an error. Are all the answers wrong or what? Please clarify.

Thank u
rajani

[This message has been edited by rajani peddi (edited December 21, 2000).]
 
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bill I only like A, thats the only one that makes the correct use of the start() and run() methods, do you need more explanation on this ?
 
bill bozeman
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
rajani, post your code that tried to use so we can see it. A should be the only correct answer.
sarim, you don't need to post more detail as long as you understand why A is correct and why the rest are not.
Here is my reasoning:
A true - This creates an anonymous class that implements Runnable, creates a thread passing in the implentation of Runnable, then starts the thread.
B false - This creates an anonymous class that extends Thread, but they don't override Thread's run method, so the Thread never starts. Since you are overriding Threads start method, it will run, but it is not creating a Thread and calling Thread's start method which schedules it with the Thread Schedular.
C false - This creates an anonymous class that implements Runnable, but never creates the Thread so you will get a compile error as r has no start() method.
D false - This creates a new Thread where you pass in an object Work, but there is no constructor in the Thread class that supports objects unless the object implements Runnable, which Work never said it did. You can pass in an object that implements Runnable, a string for the object name, or a ThreadGroup object
E false - The creates an anonymous class that implements Runnable, but it doesn't create a new Thread and call the start method of the new thread. This will compile, but it doesn't create a new thread.
Just my thoughts on the answers. This one I got right the first time through (one of only a few that I got right the first time through )
Bill

[This message has been edited by bill bozeman (edited December 21, 2000).]
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The code A,B and E are compiling successfully and call the doIt() but the code A is starting a new thread.
 
rajani peddi
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bill,
I made a mistake in writing the program. When you have asked me to post it here i have double checked it and then found my error.
Thank u
rajani
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good question Bill ..
Folks,
Here is what I think..correct me if I am wrong
A: Correct Answer
B: Incorrect and the trap. Starts a new thread but the work is not done by that thread.
C:Compile Error.
D:Compile Error.
E:Where is my thread?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic