Multiple choice technology programming languages

Which statement is true for the following code? public class Rpcraven { public static void main(String argv[]){ Pmcraven pm1 = new Pmcraven("one"); pm1.run(); Pmcraven pm2 = new Pmcraven("two"); pm2.run(); } } class Pmcraven extends Thread { private String sTname=""; Pmcraven(String s) { sTname = s; } public void run(){ for(int i =0; i < 2 ; i++){ try { sleep(1000); }catch(InterruptedException e){ } yield(); System.out.println(sTname); } } }

  1. Compile time error, class Rpcraven does not import java.lang.Thread

  2. Output of One One Two Two

  3. Output of One Two One Two

  4. Output of One Two Two One

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

When run() is called directly on a Thread (instead of start()), it executes in the calling thread without creating a new thread. The two Pmcraven objects execute sequentially: pm1's run() completes (printing 'one' twice), then pm2's run() completes (printing 'two' twice). Options C and D incorrectly suggest interleaving, which would only occur with proper thread startup using start().

AI explanation

The code calls pm1.run() and pm2.run() directly instead of pm1.start()/pm2.start(), so no new threads are actually created — each run() call executes synchronously on the main thread and must finish before the next statement runs. pm1.run() loops twice printing "one", completing fully before pm2 = new Pmcraven("two") is even constructed and run, so the output is deterministically "One One Two Two". Calling sleep/yield inside run() doesn't change this since there's no concurrent thread to yield to.