To answer this question, let's go through each option to understand why it is correct or incorrect:
Option A) Compile time error, class Rpcraven does not import java.lang.Thread - This option is incorrect. The java.lang.Thread
class is part of the Java standard library and does not require an explicit import statement.
Option B) Output of One One Two Two - This option is correct. The main
method creates two instances of the Pmcraven
class, passing "one" and "two" as arguments to the constructor. Each instance of Pmcraven
is a separate thread. When the run
method is called on each thread, it prints the value of sTname
twice, resulting in the output "One One Two Two".
Option C) Output of One Two One Two - This option is incorrect. The run
method of Pmcraven
does not alternate the printing of "One" and "Two". Instead, it prints the value of sTname
twice in a row before moving on to the next thread.
Option D) Output of One Two Two One - This option is incorrect. The run
method of Pmcraven
does not print "Two" before printing "One" for the second time. Instead, it prints the value of sTname
twice in a row before moving on to the next thread.
The correct answer is B. This option is correct because the output of the code will be "One One Two Two" as explained above.