Skip to content
Related Articles
Open in App
Not now

Related Articles

Java | Data Types | Question 2

Improve Article
Save Article
  • Difficulty Level : Hard
  • Last Updated : 28 Jun, 2021
Improve Article
Save Article

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

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!