Java - What is the output:label and block

Question

What is the output?

public class Main {
  public static void main(String[] args) {
    System.out.println("a");
    lab1: {
      int i = 10;
      System.out.println("b");
      if (i == 10)
        break lab1; 
    }
    System.out.println("c");
    lab2: {
      int i = 10;
      if (i == 10)
        break lab1;
    }
    System.out.println("d");
  }
}


Click to view the answer

lab2: {
      int i = 10;
      if (i == 10)
        break lab1;// A compile-time error.
}

Note

lab1 cannot be used here because the block is not associated with lab1 label.

Related Quiz