Which interface or class should a class use or extend to create a new thread in Java?
- Executor
- Runnable
- Thread
- java.lang
In Java, to create a new thread, a class should implement the Runnable interface. The Runnable interface defines a single abstract method, run(), which should be overridden to provide the code that the new thread will execute. The other options are not used for directly creating a new thread.
Loading...
Related Quiz
- Deadlocks involving synchronized methods or blocks can potentially be resolved by ________.
- What happens if no constructor is provided in a Java class?
- In a multi-threaded server application, what could be a potential issue if each thread opens its own database connection via a socket?
- How does the FileWriter class handle character encoding?
- What is the impact on memory usage when declaring a large two-dimensional array with most elements being zero?