Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Java Code not working  RSS feed

 
Harish Vembu
Ranch Hand
Posts: 33
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why the Below code dosen't compile and compiles when Ttest is made non default(as given below) and but failes in runtime with main thread error

How to make it work at runutime?

Please excuse me if my question is very simple. I am prepared to pay fine
;-)

Thanks & Regards,

Harish.V
[ September 08, 2005: Message edited by: Michael Ernest ]
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't understand your question, exactly, but I can tell you that by overriding the "start" method of java.lang.Thread, you're preventing the Thread from starting; when you call start() on a Ttest1 instance, it's your overridden start() that will be called, not the one supplied by java.lang.Thread, and yours doesn't do anything, so the Thread won't be started.

I don't know what you mean about "failing with a main thread error" -- what error message are you seeing? I'd expect this code to execute and print

Hey you!
s1
r2
 
Michael Ernest
High Plains Drifter
Sheriff
Posts: 7292
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's the output I got:

What were you expecting?
 
Daniel Prene
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
just as a tip, check out http://java.sun.com/docs/codeconv/
 
Harish Vembu
Ranch Hand
Posts: 33
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Michael,
Yes you are right I got the correct output as you had mentioned. I had saved the file with wrong name that's the reason I got this error message.

But now comes up another question :

Why we have the o/p as
s1 and r2 and not s1 and s2

Is it because Ttest2 implements runnable interface?

Thanks Again

Harish.V
 
Michael Lloyd Lee
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> Is it because Ttest2 implements runnable interface?

yeap.

I know it has been said a number of times before, but don't extend Thread unless you have a very good reason to.
Call super.<method name> when you want the effects of that method, as well as your overrided method.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!