We can declare thread in class using two ways
extends Thread
classimplements Runnable
interface
so which scenario is the best way?
We can declare thread in class using two ways
extends Thread
classimplements Runnable
interfaceso which scenario is the best way?
There is no "best", they're both good. There is most appropriate, though.
For over 90% of the cases, implementing Runnable is the way to go. You should never extend Thread, unless you need to change the functionality provided by the Thread class.
You should implement Runnable, since you can extend only one class, and you might want to use it to extend something that cannot be implemented.