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: Implementing the Runnable interface

Creating a thread: Implementing the Runnable interface - Java Tutorial

From the course: Java Threads

Creating a thread: Implementing the Runnable interface

- [Instructor] The second way to create a thread is by implementing the Runnable interface. To demonstrate this way of creating a thread, I've added a Java class named MyRunnable. Next, I'm implementing the MyRunnable class by the Runnable interface. So I'll type implements Runnable. Now you can see Intellij showing that there's an error. It says, Class MyRunnable must either be declared abstract or implement abstract method run in Runnable. This is because the Runnable interface defines just one method named run. And any class implementing the Runnable interface should implement this run method. You can do this either by typing the syntax of the run method or, since you are using the IDE, simply by clicking on the implement method's link here on the error message. So yes, we want to implement the public void run method of the Runnable interface. Go ahead and click OK. And there you have it, the skeleton of the…

Contents