Create thread in Java

The Thread class is the main class for creating and executing thread in Java. We can use this class in two ways: 1. Create a subclass of Thread class and overriding it’s run() method. 2. Create an instance of Runnable interface and creating a Thread object with this. Note: The Thread class is also implementing Runnable interface. Now let us see this two approaches with code examples: 1. Thread class with overriding run() method Create a subclass named SampleThread extending Thread: