问题详情

boolean bool = true; if(bool = false) { System.out.println(“a”); } else if (bool) { System.out.println(“c”); } else if (!bool) { System.out.println(“c”); } else { System.out.println(“d”); } What is the result?()  


A、 a

B、 b

C、 c

D、 d

E、 Compilation fails.

时间:2022-01-12 08:35 关键词: CMS专题 Java认证考试 SCJP程序员认证考试

答案解析

C
First of all, the second println statement should print the character ‘b’ instead of ‘c’. Also, the answer is not E. but C. Indeed, the following line is perfectly legal: if ‘(bool = false)’. The bool variable will simply take the value of false and the IF statement will be evaluated to false. Therefore, the correct answer is C.