Which of the following constructor of class Thread is valid one?
A. Thread(Runnable threadOb, int priority)
B. Thread(int priority)
C. Thread(Runnable threadOb, String threadName)
D. Thread(String threadName, int priority)
E. None of these
Answer: Option C
Solution(By Examveda Team)
A. Thread(Runnable threadOb, int priority)This constructor is invalid because the
Thread
class does not have a constructor that takes a Runnable
object and an int
priority as arguments.B. Thread(int priority)
This constructor is invalid because the
Thread
class does not have a constructor that takes only an int
priority as an argument.C. Thread(Runnable threadOb, String threadName)
This constructor is valid. It creates a new thread with the provided
Runnable
object and assigns it the specified name.D. Thread(String threadName, int priority)
This constructor is invalid because the
Thread
class does not have a constructor that takes both a String
thread name and an int
priority as arguments.E. None of these
This option is incorrect because option C, "Thread(Runnable threadOb, String threadName)," is a valid constructor for the
Thread
class.Therefore, the correct answer is:
C. Thread(Runnable threadOb, String threadName)
Join The Discussion
Comments ( 2 )
A. A lightweight process that runs independently within a program
B. A data structure to store variables
C. A type of loop
D. A synchronization mechanism
Which interface is used to create a thread in Java?
A. Processor
B. Executor
C. Threadable
D. Runnable
What is the main advantage of using multithreading in Java programs?
A. Reduced memory usage
B. Simplicity of code
C. Improved program performance by utilizing multiple CPUs or CPU cores
D. Elimination of exceptions
How can you create a new thread in Java by implementing the Runnable interface?
A. Create an object of the Thread class
B. Create a class that implements the Runnable interface and override the run() method
C. Use the start() method of the main thread
D. Create an object of the Thread class
Thread(Runnable target, String name): This constructor creates a new thread object with the specified target Runnable and the specified name.
How?