Skip to content
Related Articles

Related Articles

Java | Data Types | Question 2
  • Last Updated : 07 Jan, 2014
GeeksforGeeks - Summer Carnival Banner

Predict the output of following Java program.

class Test { 
    public static void main(String[] args) { 
      for(int i = 0; 0; i++) 

(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

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :