We can create a thread in Java by extending Thread Class.
A better way to create a thread in Java is to implement Runnable
interface. A thread can be created by extending Java Thread class also.
Now the question arises why implementing Runnable interface is a better
approach? Answer is, if the thread class you are creating is to be
subclass of some other class, it can’t extend from the Thread class.
This is because Java does not allow a class to inherit from more than
one class. In such a case one can use Runnable interface to implement
threads.
Let us see an example of creating a thread by implementing Runnable interface. more...
Let us see an example of creating a thread by implementing Runnable interface. more...
No comments:
Post a Comment