rahul rahul - 2 months ago 7
Java Question

Why does 'extends Thread' exist, when 'implements Runnable' is winner in all cases

I know that

is preferred over
extends Thread
in Java threads as it allows us to extend some other class if it is required. But if this is the case, does
extends Thread
also have its own advantages over
implements Runnable
and if so, what are these advantages?

Answer

Because sometimes (almost never, but sometimes) you want to be able to change the basic behaviour of Thread.

That's when you'll need to extend it.

You can change it by overriding a method from the Thread class, you can't do it by implementing one from Runnable.