Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
307 views
in Programming by (106k points)
closed by

Consider the following Java code fragment. Which of the following statement is true?

Line No

Code Statement

1

public class While

2

{

3

      public void loop()

4

      {

5

         int x = 0;

6

         while (1)

7

          {

8

System.out.println(“x plus one is” + (x + 1));

9

           }

10

      }

11

}


1. There is syntax error in line no. 1
2. There are 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 Answer

0 votes
by (106k points)
selected by
 
Best answer
Correct Answer - Option 4 : There is syntax error in line no. 6

The correct answer is “option 4”.

EXPLANATION:

Option 1: FALSE

While” is notkeyword, hence it is valid to use it as a class name.

Option 2: FALSE

Since Option 1 is false, so this option is by default false.

Option 3: FALSE

Any string operation can contain an equation type of expression.

So, this is not any kind of syntax error.

Option 4: TRUE

Java uses condition as Boolean expressions like:   

while(true) or while(false)

Hence, while(1) is the wrong syntax for java.

while(1) will give compiler time error as it treats as type mismatch to convert from integer to boolean value.

Hence, the correct answer is “option 4”.

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...