Java OCA OCP Practice Question 845

Question

What will the following program print?

public class Main{ 
  public static void main (String [] args){ 
     for  : for (int i = 0; i< 10; i++){ 
        for  (int j = 0; j< 10; j++){ 
             if  ( i+ j > 10 )  break for; 
         } /*  ww  w. j  a  v a 2 s  .co m*/
        System .out.println ( "hello"); 
      } 
   } 
} 

Select 1 option

  • A. It will print hello 6 times.
  • B. It will not compile.
  • C. It will print hello 2 times.
  • D. It will print hello 5 times.
  • E. It will print hello 4 times.


Correct Option is  : B

Note

Note that for is a keyword and so cannot be used as a label.

But you can use any other identifier as a label.




PreviousNext

Related