Tuesday, 17 November 2015

What are the two ways of creating thread

There are 2 ways of creating thread.
 a) extends Thread class
 b) implements Runnable interface
a)
extends Thread: extends Thread class and override the run() method in your class. Create an instance of the subclass and invoke the start() method on it, which will create a new thread of execution.
 
b) implements Runnable: The class will have to implement the run() method in the Runnable interface. Create an instance of this class. Pass the reference of this instance to the Thread constructor a new thread of execution will be created.

No comments:

Post a Comment