Thursday, 22 December 2016

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

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...