From the course: Java Threads

Unlock the full course today

Join today to access over 24,400 courses taught by industry experts.

Creating a thread: Extending the Thread class

Creating a thread: Extending the Thread class - Java Tutorial

From the course: Java Threads

Creating a thread: Extending the Thread class

- [Instructor] There are two ways to create a Java thread. By extending the java.lang.Thread class and by implementing the java.lang.Runnable interface. In this video, I'll demonstrate the first way of creating a thread, that is, by extending the thread class. I created a Java class named FirstThread. This is a normal Java class, and now I want to make this a thread class. To do that, I simply have to extend it by the thread class. So, extends Thread. So now my first thread class is a subclass of the thread class, that gives it all the attributes and the behavior that it should have to become a Java thread. I need to do one more thing to make this thread runnable so that it becomes an official thread. To do that, I should override the run method of the thread super class. So I'll type public void run. It's always good practice to add @Override annotation here above the method. So I'll go ahead and add @Override.…

Contents