in Java edited by
3,622 views
2 votes
2 votes

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
in Java edited by
3.6k views

1 comment

I think syntactically all the lines are correct
0
0

3 Answers

15 votes
15 votes
Best answer
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
selected by

4 Comments

thank u
0
0
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???
1
1
its just declaration of class na
0
0
edited by

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

0
0
1 vote
1 vote
No syntax error..
by

2 Comments

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
0
0
Java is case-sensitive. So, while while is a keyword, While is not.
7
7
0 votes
0 votes
I think answer is A as we cannot have class While

2 Comments

Divya Bharti

The class name is While not while keyword

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

4
4
ok,Thank you
0
0
Answer:

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true