Java | Data Types | Question 2

Predict the output of following Java program.

filter_none

edit
close

play_arrow

link
brightness_4
code

class Test { 
    public static void main(String[] args) { 
      for(int i = 0; 0; i++) 
      
          System.out.println("Hello"); 
          break
      
    

chevron_right


(A) Hello
(B) Empty Output
(C) Compiler error
(D) Runtime error


Answer: (C)

Explanation: The error is in for loop where 0 is used in place of boolean value.

Unlike C++, use of non boolean variables in place of bool is not allowed

Quiz of this Question



My Personal Notes arrow_drop_up


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.