Home Tutorial Java Scjp Part5 SCJP Module-5 Question-13

 
 

SCJP Module-5 Question-13
Posted on: July 22, 2010 at 12:00 AM
The program given below will test your understanding about the use of break key word in Java.

Given a sample code:

1    public class Test2 {
2    public static void main(String[] args) {
3    System.out.println("Hello");
4    break;
5    System.out.println("Hi");
}}

What will be result when compiled and run?

(A)  Hello
(B)  Hello Hi   
(C)  Runtime exception.  
(D)  Compilation error at line no-4.   

Answer:

(D)

Explanation:

break cannot be used outside of a loop or a switch

Related Tags for SCJP Module-5 Question-13: