I suggest you ...

Thread Question is wrong!

The following Thread question is wrong:
(following the question -- in question -- I have shown a the class with a brief alteration that show the answer should be "the results can not be predicted")
----------------------------------------------------------
Given the code. What is the result?
public class Cruiser implements Runnable {
public static void main(String[] args) throws InterruptedException {
Thread a = new Thread(new Cruiser());
a.start();

System.out.print("Begin");
a.join();
System.out.print("End");
}

public void run() {
System.out.print("Run");
}
}
A) Compilation fails.
B) An exception is thrown at runtime.
C) "BeginRunEnd" is printed.
D) "BeginEndRun" is printed.
E) "BeginEnd" is printed.
----------------------------------------------------------
//my suggested question change
----------------------------------------------------------

public class Cruiser2 implements Runnable {
static int lc = 100;
//desired effect is in order BeginRunEnd
public static void main(String[] args) throws InterruptedException {

Thread a = new Thread(new Cruiser2());
a.start();

for(int i = 0; i < lc; i++)
System.out.println("Begin Main");

a.join();
for(int i = 0; i < lc; i++)
System.out.println("End");
}

public void run() {
for(int i = 0; i < lc; i++)
System.out.println("Run Thread a");
}
}

25 votes
Vote
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    Signed in as (Sign out)
    You have left! (?) (thinking…)
    anonymous shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

    8 comments

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      Signed in as (Sign out)
      Submitting...

      Feedback and Knowledge Base