• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question on Threads

 
Mohit G Gupta
Ranch Hand
Posts: 634
Chrome Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kb Book THreads Self-test pg-782






And given the following five fragments:
I. new Starter().run();
II. new Starter().start();
III. new Thread(new Starter());
IV. new Thread(new Starter()).run();
V. new Thread(new Starter()).start();

When the five fragments are inserted, one at a time at line 9, which are true? (Choose all that apply.)
A. All five will compile
B. Only one might produce the output 4 4
C. Only one might produce the output 4 2
D. Exactly two might produce the output 4 4
E. Exactly two might produce the output 4 2
F. Exactly three might produce the output 4 4
G. Exactly three might produce the output 4 2


Ans: C And D


i too think that C is correct but how's D possible.can anyone explain

only III,IV V would work when inserted ,but only V would result in any output.
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For D, What about fragment I and IV?
 
Mohit G Gupta
Ranch Hand
Posts: 634
Chrome Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what do you mean to say Abimaran Kugathasan ?
 
Henry Wong
author
Marshal
Pie
Posts: 20836
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
mohitkumar gupta wrote:what do you mean to say Abimaran Kugathasan ?


He means... why don't you think I and IV will run, and produce any output?

Henry
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
mohitkumar gupta wrote:what do you mean to say Abimaran Kugathasan ?


The fragments I and IV will work, and the output may be 4 4. (We can't tell sure that Thread ID is 4, but for this question, it'll print same ID, because same thread will run in the code)
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And, Henry, could you please check your private message regarding a topic?

Thanks in Advanced!
 
Vijitha Kumara
Bartender
Posts: 3908
9
Chrome Fedora Hibernate
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The fragments I and IV will work, and the output may be 4 4. (We can't tell sure that Thread ID is 4, but for this question, it'll print same ID, because same thread will run in the code)

That's why the answer says "Exactly two might produce the output 4 4"', It's the nature of the output not the exact value.
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vijitha Kumara wrote:
That's why the answer says "Exactly two might produce the output 4 4"', It's the nature of the output not the exact value.


Yea, The answers C and D, that's why I told it earlier!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic