0

Whats the difference between Thread run() method and run() method I make my self.

Because I see that when I extend this class I override this method which alters the original version right? and that part makes no sense to me. Thanks

28th Oct 2020, 10:19 AM
Nobody
Nobody - avatar
1 Antwort
+ 4
The run() method from Thread class is used to perform some operation using a separate thread of that class. Calling the run() method using the class name does not create a new thread. You must make use of the Thread class object for that. For eg: if you have a class X that implements the Runnable interface then you must say- Thread th = new Thread(new X()); th.start(); Or you can extend Thread class and say- X th = new X(); th.start(); Both will create a new thread. ---------------------------------------------- The run() from Thread class has no implementation which gives you the privilege to put your own implementation and use it. If you don't override it then the run() of Thread class will be called and it does nothing.
28th Oct 2020, 10:48 AM
Avinesh
Avinesh - avatar