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 ?
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.