3,622 views

Consider the following Java code fragment:

public class While
{
public void loop()
{
int x = 0;
while(1)
{
System.out.println("x plus one is" +(x+1));
}
}
}
1. There is syntax error in line no. 1
2. There is syntax errors in line nos. 1 & 6
3. There is syntax error in line no. 8
4. There is syntax error in line no. 6

### 1 comment

I think syntactically all the lines are correct

In Java, while(1) will give compiler time error as it treats as Type mismatch to convert from int to Bool value. Hence Ans :D
by

thank u
but there is implicit conversion also ..so java compiler will take care of that I think error is at Line-1, where While is used..compiler can't recognise While..ryt???
its just declaration of class na
edited

While is a keyword right ? so how can we use it as class name ? I think 1 & 6 line no. have errors.

Sorry! my mistake I wasn't aware of this concept in java :  yes only line no. 6 will give error.. please check the below link

https://stackoverflow.com/questions/30491035/can-java-class-files-use-reserved-keywords-as-names

No syntax error..
by

As While is a keyword and we can not use keywords as class name..so I think answer is option 1..correct me if wrong
Java is case-sensitive. So, while while is a keyword, While is not.
I think answer is A as we cannot have class While

The class name is While not while keyword

it does not treat it as a keyword as java is case sensitive

ok,Thank you