Mastering Java: The Ultimate Quiz for 'Thinking in Java'

Disable ads (and more) with a membership for a one time $2.99 payment

Mastering Java: The Ultimate Quiz for 'Thinking in Java'. Dive deep into Java with multiple-choice questions. Challenge yourself with quiz questions designed to test and improve your understanding of the 'Thinking in Java' book. Get ready for your exam!

Practice this question and more.


How can a thread be created using Runnable interface?

  1. By extending the Runnable class

  2. By implementing the Runnable interface and defining the run() method

  3. By calling the run() method

  4. By instantiating the Runnable interface directly

The correct answer is: By implementing the Runnable interface and defining the run() method

A This option is incorrect because in Java, extending the Runnable class is another way to create a thread but it is not an option mentioned in the question which specifically mentions using the Runnable interface. C: This option is incorrect because calling the run() method will not create a new thread. It will simply execute the code in the calling thread. D: This option is incorrect because we cannot instantiate interfaces directly in Java. Interfaces are meant to be implemented by classes. In order to create a thread using the Runnable interface, we must implement the interface and define the run() method, as mentioned in option B. The run() method contains the code that will be executed when the thread is started. Therefore, option B is the correct answer.