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)); } } } There is syntax error in line no. 1 There is syntax errors in line nos. 1 & 6 There is syntax error in line no. 8 There is syntax error in line no. 6 Java isro2014 java non-gate + – shivanisrivarshini asked Jun 27, 2016 • edited Jun 28, 2016 by Anu shivanisrivarshini 5.0k views answer comment Share Follow See 1 comment See all 1 1 comment reply shivanisrivarshini commented Jun 27, 2016 reply Follow Share I think syntactically all the lines are correct 0 votes 0 votes Please log in or register to add a comment.
Best answer 17 votes 17 votes 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 pps121 answered Jun 28, 2016 • selected Jun 28, 2016 by shivanisrivarshini pps121 comment Share Follow See all 4 Comments See all 4 4 Comments reply shivanisrivarshini commented Jun 28, 2016 reply Follow Share thank u 0 votes 0 votes cse23 commented Jun 30, 2016 reply Follow Share 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 votes 1 votes shivanisrivarshini commented Jun 30, 2016 reply Follow Share its just declaration of class na 0 votes 0 votes Raju Kalagoni commented Nov 24, 2019 i edited by Raju Kalagoni Nov 24, 2019 reply Follow Share 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 votes 0 votes Please log in or register to add a comment.
1 votes 1 votes No syntax error.. cse23 answered Jun 27, 2016 cse23 comment Share Follow See all 2 Comments See all 2 2 Comments reply RUPALIBarse commented Jul 2, 2016 reply Follow Share 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 votes 0 votes TestUser commented Jul 2, 2016 reply Follow Share Java is case-sensitive. So, while while is a keyword, While is not. 7 votes 7 votes Please log in or register to add a comment.
0 votes 0 votes I think answer is A as we cannot have class While Regina Phalange answered Apr 5, 2017 Regina Phalange comment Share Follow See all 2 Comments See all 2 2 Comments reply dattasai commented Apr 6, 2017 reply Follow Share @ Divya Bharti The class name is While not while keyword it does not treat it as a keyword as java is case sensitive 4 votes 4 votes Regina Phalange commented Apr 6, 2017 reply Follow Share ok,Thank you 0 votes 0 votes Please log in or register to add a comment.