1z0-829 Exam QuestionsBrowse all questions from this exam

1z0-829 Exam - Question 40


Which two code fragments compile? (Choose two.)

Show Answer
Correct Answer: AE

The code fragments that compile successfully are those that correctly follow Java programming syntax and rules. Both A and E fit these criteria. Options C, D, and F are missing the 'public static void main(String[] args)' method, which is essential for execution as a standalone Java application. Option B declares 'var a = 10', making 'a' an integer, then tries to assign a string to 'a', which is invalid. Therefore, A and E are the correct choices as they do not contain any syntax or logical errors preventing compilation.

Discussion

2 comments
Sign in to comment
supersquaxOptions: AE
Jan 31, 2024

A and E correct. C D F all wrong cuz they're missing a "public static void main(String[] args)" method B wrong cuz "var a = 10" means "a" is an "int". trying to assign a string to "a" on the next line is invalid.

xplorerpjOptions: AE
Jun 23, 2024

A & E are correct. B cannot compile because var a is initialized as integer and then a string value is assigned. C cannot compile because var cannot be initialized to null. D - Doesn't have main() F - Variable x already defined in scope