Topics Index

using break statement

If you need explanation Read this topic

If you need Answer Take test on this topic

using break statement
What will be the output of the following program?
public class DemoOnBreak
    public static void main(String[] args)
        Boolean b = 21 >= 21;
        block1 :
            block2 :
                block3 :
                    if (b)
                        break block2;

E. Compilation Error or Runtime Error
Topic: Using break In Nested Loop Java Program

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

Ans is D the break statement brings the control out of the it prints block1

Posted by Kiran Karrolla    2014-02-28 13:20:59

Ans is D since boolean takes true value and if(true) is yes and break block wit label block2  is happend and prints last system.out statement Block1 so ans is D......:)

Posted by Naga Sinst    2014-02-28 13:21:52

ans is D bcz boolean b takes true value and then the if conditon satisfies n breaks out of block2 and prints"BLOCK1"

Posted by Pooja Singh    2014-02-28 15:05:47

ans is D as the operator >= has higher precedence than = operator therefore 21>=21 will execute first ..its results is 1. then in if (b) command will exxecute after blocks...hence break of block2 will execute n hence it will come out of block2.Automatically we can say it is not in block 3 as it is in the block 2...... then the block1 commnad executes ... hencce the ans is D.

Posted by Sai Abhishek    2014-02-28 19:27:42


Posted by Chandu Chandrahas    2014-03-03 04:30:20

Congratulations Pooja Singh. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-03-03 09:17:35

© meritcampus 2019

All Rights Reserved.

Open In App