Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Urgent plzzzzzz help!!

 
himanshu kesarwani
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

i am shocked after this question java is really very very unpredictable,its just compillers mood that decide what to run and what to not....
lookin at start(); method compiler forgets that its a thread and it should call run(); instead it prefered THE start();
..........!!
i cant bear it any more, on 1st april i am having scjp exam and such type of questions are making me nervous!!
but still i am determined...to beat scjp !!
 
Treimin Clark
Ranch Hand
Posts: 757
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rules: UseAMeaningfulSubjectLine, EaseUp, QuoteYourSources
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What else would you expect if you override the Thread.start method? Its javadocs clearly mention that one of its purposes is to create a new thread and then call its "run" method.

This is a good example of why you should almost never (and certainly not here) extend Thread, but instead implement Runnable: ExtendingThreadVsImplementingRunnable
 
Abhi Kumar
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello himanshu kesarwani !!
Initially look at the code, you are creating the object of Th and not that of Thread class.
The compiler treats start() as a local method to the class Th , and invokes the start method.

If you create a Thread object and call the start method then you can see the run() method being invoked
Regards
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic