I would expect the output to be a compilation error. Java is case sensitive and you have made some errors with your case when referring to your classes.
Also note that by convention classes in Java should start with a capital letter, and variable and method names should start with a lower case letter.
But assuming you fix the compilation error what do you expect the output to be? Have you tested it to see if you're right?
There might be some typing errors..but when I compiled it is calling run() of the class extending Thread ..but shouldn't it call run() of the class implementing Runnable because the constructor Thread(Runnable runnable) calls run() of the runnable instance? Please explain.
This would print Hello T1 but when we pass a reference of a class implementing Runnable to the Thread class directly then the run() of the class implementing Runnable is executed then in this why isn't that happening because a runnable reference is passed to the Thread class ..this is my doubt..please explain
Well as you understand, when a thread is started its run() method is called, so let's have a look at the contents of run() in Thread...
'target' is the Runnable instance that was passed to the Thread in its constructor. So as you can see, Thread's run() method will always delegate to the Runnable instance that it was constructed with.
However in the case of your class t1 (which should be called T1), the run() method in Thread is not being run. You have overridden it, so the run() method in t1 is run instead.
For my next feat, I will require a volunteer from the audience! Perhaps this tiny ad?
Gift giving made easy with the permaculture playing cards