What will be the result of the following program execution?

public class Abc {
    public static void main(String[] args) {
    p1:
        {
        p2:   
            {
            p3:
                {
                    System.out.print("p3.1 ");
                    if (true) break p2;
                    System.out.print("p3.2 ");
                }
                System.out.print("p2 ");
            }
            System.out.print("p1 ");
        }
    }
}
Explanation
Not only loops, conditions, etc. can be labeled but also a normal block. Firstly the program will print string p3.1, then the condition will be executed - the transitioning for a block of code labeled p2 will be executed and it will print p1.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
Java quizzes
Cosmo
Sign Up Now
or Subscribe for future quizzes