Learn the three valid initialization statements from the given options for the Oracle Java SE 11 Developer 1z0-819 certification exam. Enhance your Java skills and ace the certification.
Table of Contents
Question
Which three initialization statements are valid? (Choose three.)
A. var loc = Arrays.of(“UK”, “US”, “ES”);
B. var loc = List.of(“UK”, “US”);
C. var loc = List.of(“UK”, null, “US”);
D. var loc = Map.of(“UK”, 1, “US”, 2);
E. var loc = ArrayList.of(“UK”, “US”);
F. var loc = Set.of(“UK”, “US”, “UK”);
G. var loc = Set.of(“UK”, “US”);
Answer
B. var loc = List.of(“UK”, “US”);
C. var loc = List.of(“UK”, null, “US”);
G. var loc = Set.of(“UK”, “US”);
Explanation
The three valid initialization statements are:
B. var loc = List.of(“UK”, “US”);
C. var loc = List.of(“UK”, null, “US”);
G. var loc = Set.of(“UK”, “US”);
Explanation:
B and C utilize the List.of() method introduced in Java 9, which creates an immutable List instance with the provided elements.
G uses the Set.of() method, also introduced in Java 9, to create an immutable Set instance with the given elements. It automatically removes duplicates, so the resulting set will contain only one instance of “UK” and “US”.
A is invalid because Arrays.of() is not a valid method in Java.
D is invalid because Map.of() expects an even number of arguments, where each pair represents a key-value entry for the Map.
E is invalid because there is no static of() method in the ArrayList class.
F is invalid because it attempts to create a Set with duplicate elements (“UK” appears twice), which is not allowed in Sets.
Oracle Java SE 11 Developer 1z0-819 certification exam practice question and answer (Q&A) dump with detail explanation and reference available free, helpful to pass the Oracle Java SE 11 Developer 1z0-819 exam and earn Oracle Java SE 11 Developer 1z0-819 certification.