Question 63

Consider the following Java code segment: public class while /* line 1*/

Consider the following Java code segment: public class while /* line 1*/ { public void loop ( ) { int x = 0; While (1)/* line-6*/ { system. out. println("x plus one is" + (x+1)): } } } Which of the following is true ?
  1. AThere is a syntax error in line-1
  2. BThere are syntax errors in line- 1 and line- 6
  3. CThere is a syntax error in line- 6
  4. DNo syntax error
Show answerHide answer

Correct answer: (A) There is a syntax error in line-1

Explanation

while is a reserved keyword in Java, so it cannot be used as a class name. "public class while" is a syntax error on line 1.

From DSSSB TGT Computer Science Practice Set 4

This is question 63 of DSSSB TGT Computer Science Practice Set 4. See all questions of this paper with answers, or attempt the paper as a timed online test to get your score and all-India rank.