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

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

Dive into the depths of Java with our quiz based on "Thinking in Java, Fourth Edition" by Bruce Eckel. Test your knowledge, solidify concepts, and prepare for certification with challenging questions and insightful feedback.

Each practice test/flash card set has 50 randomly selected questions from a bank of over 500. You'll get a new set of questions each time!

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.