Menu
Topics Index
...
`

Print different statements


If you need explanation Read this topic

If you need Answer Take test on this topic

Print different statements
What will be the output of the following program?
public class TwoInOneBook {
    public static void main(String[] args) {
        boolean b = true;
        One : {
            Two : {
                Book : {
                    System.out.println("Book block");
                    if (b) {
                        break Two;
                    }
                    System.out.println("Book block printed after break Two block");
                }
            }
            System.out.println("One block");
        }
        System.out.println("Main block");
    }
}

A. Book block
Book block printed after break Two block
One block
Main block
B. Book block
One block
Main block
C. Compilation Error
D. Runtime Error
Topic: Using Java Break Statements as Java Goto

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:B  first print " book block" and then enter into if because b is true. Because of break it terminates book,two blocks. then prints " one block" and " main block"

Posted by Indrasena Reddy    2014-01-21 08:48:31


Anser is B : 1stly it prints the Book block, then Two Block will break since b is true, goes out of Two block and excutes the one block then main block !!

Posted by Shaik Nyamath    2014-01-21 08:51:14


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

Posted by Merit Campus    2014-01-22 04:02:21


© meritcampus 2019

All Rights Reserved.

Open In App