-2
    public class Messager implements Runnable {
      public static void main(String[] args) {
        new Thread(new Messager("Wallace")).start();
        new Thread(new Messager("Gromit")).start();
    }
     private String name;
     public Messager(String name) {
         this.name = name;
     }
     public void run() {
      message(1);
      message(2);
    }
     private synchronized void message(int n) {
      System.out.print(name + "-" + n + " ");
     }
  }

is : B. Wallace-1 Gromit-2 Wallace-2 Gromit-1 a possible result of the execution of this code?

Nathan Hughes
  • 94,330
  • 19
  • 181
  • 276
user199
  • 107
  • 10

1 Answers1

1

No, it is not a possible result.

message(1) and message(2) are executed in the order.

So, Gromit-1 must be followed by Gromit-2.