I only had one line with compile time errors in the first code block.Crystal Kirscht wrote:. . . " The code contains two lines that do not compile."
Both errors are about the default.jshell> void printType(Object o) {
...> if(o instanceof Integer bat) {
...> System.out.print("int");
...> } else if(o instanceof Integer bat && bat < 10) {
...> System.out.print("small int");
...> } else if(o instanceof Long bat || bat = 20) {
...> System.out.print("long");
...> } default {
...> System.out.print("unknown");
...> }
...> }
| Error:
| orphaned default
| } default {
| ^
| Error:
| : or -> expected
| } default {
| ^
I think you are probably correct; that should go down as an erratum.. . . I don't know where 's' came from, I'm assuming they mean 'o'
Crystal Kirscht wrote:Why is the duplicate variable declaration allowed in question 8 but not in question 28?
[OCP 21 book] | [OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
[OCP 21 book] | [OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2