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

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

Prepare for your Java exam with our ultimate quiz based on 'Thinking in Java'. Engage with expertly crafted questions that enhance your learning process. Perfect for Java enthusiasts looking to solidify their knowledge!

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.