ISRO Computer Science (CSE) 2014 - Question 29

All ISRO Computer Science (CSE) papers | ISRO Computer Science (CSE) 2014

Consider the following Java code fragment.\n```java\n1. Public class while \n2. { \n3. Public void loop() \n4. { \n5. int x = 0; \n6. while(1) \n7. { \n8. system.out.println("x plus one is" + (x + 1)); \n9. } \n10. } \n11. }\n```\nWhich of the following statements is true?

  • A. There is syntax error in line no. 1
  • B. There is syntax error in line no. 1 and 6
  • C. There is syntax error in line no. 8
  • D. There is syntax error in line no. 6

Answer: B. There is syntax error in line no. 1 and 6

Explanation: Line 1: `while` is a keyword, cannot be a class name.\nLine 6: `while(1)` is invalid in Java; it must be `while(true)` (boolean).

| | All questions of ISRO Computer Science (CSE) 2014