Which method must be defined by a class implementing the java.lang.Runnable interface?

  1. void run()

  2. public void run()

  3. public void start()

  4. void run(int priority)


Correct Option: B

AI Explanation

To answer this question, you need to understand the java.lang.Runnable interface.

The java.lang.Runnable interface is used to define a task that can be executed by a thread. It contains only one method that must be implemented by any class that implements this interface.

The method that must be defined by a class implementing the java.lang.Runnable interface is:

Option B) public void run()

This method represents the task that will be executed when a thread is started. It does not take any arguments and does not return any value. The implementation of this method should contain the code that defines the task to be performed by the thread.

Option A) void run() - This option is incorrect because the run() method must be defined as public when implementing the java.lang.Runnable interface.

Option C) public void start() - This option is incorrect because the start() method is not part of the java.lang.Runnable interface. The start() method is a method of the Thread class, which is used to start a new thread.

Option D) void run(int priority) - This option is incorrect because the run() method in the java.lang.Runnable interface does not take any arguments.

Find more quizzes: