Exam 1z0-811 All QuestionsBrowse all questions from this exam
Question 6

Given the code fragment:

Which two code fragments are valid at line 2?

    Correct Answer: A, E

    The correct options are those that conform to Java syntax rules within a class body. Option A is valid because it includes a for loop and a print statement, both of which are valid inside a method definition in a class. Option B is invalid because 'package p1;' must be declared at the beginning of the file, not inside a class. Option C is invalid because import statements must be at the top of the file, and non-static block cannot have method declarations. Option D is invalid because a block cannot directly contain member variable declarations. Therefore, Option E is valid because it includes member variables and methods inside the class body according to Java syntax rules.

Discussion
krysitian

without reading the discussion, one could assume that all I had learned so far, were false.

falchettoOptions: DE

B is wrong because you can't declare package inside the class statement. D is correct because you can declare local variables inside a class statement, like methods (so E answer is correct aswell).

yonathanmartinezOptions: CE

B. package p1; no puede ir dentrod de la clase

Olha88Options: AC

Almost every question with an incorrect answer. What's the catch? B is NOT correct

tabrezshaikh13Options: DE

D and E are correct