Java Programming - Flow Control - Discussion

Discussion Forum : Flow Control - General Questions (Q.No. 4)
4.
public class While 
{
    public void loop() 
    {
        int x= 0;
        while ( 1 ) /* Line 6 */
        {
            System.out.print("x plus one is " + (x + 1)); /* Line 8 */
        }
    }
}
Which statement is true?
There is a syntax error on line 1.
There are syntax errors on lines 1 and 6.
There are syntax errors on lines 1, 6, and 8.
There is a syntax error on line 6.
Answer: Option
Explanation:

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.

A, B and C are incorrect because line 1 is valid (Java is case sensitive so While is a valid class name). Line 8 is also valid because an equation may be placed in a String operation as shown.

Discussion:
14 comments Page 2 of 2.

Santosh said:   1 decade ago
1. While is a key word, here all letters are small letter.

2. While, it is not a key word because it starts with Capital letter.

That's why java is a case sensitive programming language.

Naveen pandey said:   1 decade ago
To being a keyword the word must be start with capital letter. So, the use of While for class name is correct.

Naveen pandey said:   1 decade ago
To being a keyword the word must be in small letter. So the use of While will not be use as a keyword.

Nazir khan said:   6 years ago
Because java is case sensitive language that's why there is no error in line 1.


Post your comments here:

Your comments will be displayed after verification.