Exam 1z0-829 All QuestionsBrowse all questions from this exam
Question 40

Which two code fragments compile? (Choose two.)

    Correct Answer: A, E

    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
xplorerpjOptions: AE

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

supersquaxOptions: AE

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.