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 - 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.…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
Thread class and Runnable interface2m 17s
-
(Locked)
Creating a thread: Extending the Thread class4m 4s
-
(Locked)
Creating a thread: Implementing the Runnable interface3m 31s
-
(Locked)
Starting a thread7m
-
(Locked)
Extend a thread or implement a Runnable?2m 27s
-
(Locked)
Challenge: Webinar polling system3m 25s
-
(Locked)
Solution: Webinar polling system3m 33s
-
-
-