exam questions

Exam 1z0-811 All Questions

View all questions & answers for the 1z0-811 exam

Exam 1z0-811 topic 1 question 6 discussion

Actual exam question from Oracle's 1z0-811
Question #: 6
Topic #: 1
[All 1z0-811 Questions]

Given the code fragment:

Which two code fragments are valid at line 2?

  • A. for (int count = 0; count < 5; count++) {
    System.out.print(count);
    }
  • B. package p1;
  • C. import java.util.*;
    public void display() {
    List<Integer> nums = new ArrayList<> ();
    }
  • D. {
    private int num;
    }
  • E. private String name = “John”;
    public void display() {
    System.out.print(name);
    }
Show Suggested Answer Hide Answer
Suggested Answer: BE 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
electri
4 weeks ago
Selected Answer: E
E is the only correct answer, as it provides one member variable "private String name" and one method "public void display". D is not correct. It may look correct because of the member "private int num" but it's code enclosed in curly braces. There is no possibility to just dump a code block inside a class definition. It's a random code block containing "private int num", which is not correct itself also.
upvoted 1 times
...
krysitian
3 months, 4 weeks ago
without reading the discussion, one could assume that all I had learned so far, were false.
upvoted 3 times
...
tabrezshaikh13
12 months ago
Selected Answer: DE
D and E are correct
upvoted 1 times
...
falchetto
1 year, 2 months ago
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).
upvoted 3 times
...
Olha88
1 year, 3 months ago
Almost every question with an incorrect answer. What's the catch? B is NOT correct
upvoted 2 times
...
yonathanmartinez
1 year, 7 months ago
B. package p1; no puede ir dentrod de la clase
upvoted 3 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago