Skip to content
Related Articles

Related Articles

Improve Article
ISRO | ISRO CS 2014 | Question 29
  • Last Updated : 14 May, 2018

Consider the following Java code fragment:

1   public class While
2   {
3    public void loop()
4      {
5      int x = 0;
6       while(1)
7         {
8         System.out.println("x plus one is" +(x+1));
9        }
10     }
11  }

(A) There is syntax error in line no. 1
(B) There is syntax errors in line nos. 1 & 6
(C) There is syntax error in line no. 8
(D) There is syntax error in line no. 6


Answer: (D)

Explanation: Java is case sensitive so While is a valid class name as shown in line 1, so option (A) is not correct.
An equation may be placed in a String operation is valid as shown in line 8, so option (C) is not correct.

But, using the integer 1 in the while statement, or any other looping or conditional construct for that matter, will result in a compiler error. This is old C Program syntax, not valid Java as shown in line 6.
So, option (D) is correct.


Quiz of this Question

My Personal Notes arrow_drop_up
Recommended Articles
Page :