Saturday, 5 August 2017

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





I know that implements Runnable 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.


No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...