About Question enthuware.ocpjp.v7.2.1456 :
Posted: Wed Jul 24, 2013 1:35 pm
That following piece sounds strange:
1 - If your thread extends from Thread class, and if want that your class do some work, you must override the run method.
2 - Also the run's Thread Class is not a empty method, there is some code inside there that is really important to know.
So if you do like this:
Because:Note that this method is not Abstract in the Thread Class. So you need not necessarily override it. But the Thread class version
doesn't do anything. It is just empty implementation.
1 - If your thread extends from Thread class, and if want that your class do some work, you must override the run method.
2 - Also the run's Thread Class is not a empty method, there is some code inside there that is really important to know.
So if you do like this:
Code: Select all
new Thread( new X() ).run(); // It calls the run() of object that is inside Thread's constructor - . // same thread, so if you code something in X's run(), it will be executed !!
new Thread( new X()).start(); // Correct way, X's run() runs but in another Thread