Compilation Error related
Posted
by
aparna
on Stack Overflow
See other posts from Stack Overflow
or by aparna
Published on 2012-11-29T16:58:40Z
Indexed on
2012/11/29
17:03 UTC
Read the original article
Hit count: 179
Given:
11. public static void test(String str) {
12. int check = 4;
13. if (check = str.length()) {
14. System.out.print(str.charAt(check -= 1) +", ");
15. } else {
16. System.out.print(str.charAt(0) + ", ");
17. }
18. }
and the invocation:
21. test("four");
22. test("tee");
23. test("to");
What is the result?
A. r, t, t,
B. r, e, o,
C. Compilation fails.
D. An exception is thrown at runtime.
Answer: C
Can you explain why the compilation fails please?
© Stack Overflow or respective owner