• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Threads Question

 
Mohit G Gupta
Ranch Hand
Posts: 634
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
scjptest.com




A) Compilation fails.
B) An exception is thrown at runtime.
C) "go" is printed
D) "gogogo" is printed
E) "gogo" is printed
Answer: D

i think output should be c) as t.run() would call run method of Thread class
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you run this ? What is the difference between the run() and start() methods ?
 
Mohit G Gupta
Ranch Hand
Posts: 634
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
we have not defined any run method for thread class.so
t.run();
would do nothing
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15448
42
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where did you copy this question from? Please remember that you are required to QuoteYourSources on JavaRanch whenever you copy a question from a book, mock exam or other source.

What do you mean with "from SCJP TEST"? Is this from the real, actual exam? Are you aware that you are not allowed to copy the content of the real exam?
 
Trivikram Kamat
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
mohitkumar gupta wrote:
think output should be c) as t.run() would call run method of Thread class


If the Thread whose run() method is called was constructed using separate Runnable object, then that Runnable object's run method is called. Otherwise, method does nothing and returns. (from Javadocs)

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic