OCP Oracle Certified Professional Java SE 11 Developer Practice Tests. Jeanne Boyarsky

OCP Oracle Certified Professional Java SE 11 Developer Practice Tests - Jeanne Boyarsky


Скачать книгу
nums[] = new int[][] { { 0, 0 } };

      26 What does the following output?var linux = new String[] { "Linux", "Mac", "Windows" }; var mac = new String[] { "Mac", "Linux", "Windows" }; var search = Arrays.binarySearch(linux, "Linux"); var mismatch1 = Arrays.mismatch(linux, mac); var mismatch2 = Arrays.mismatch(mac, mac); System.out.println(search + " " + mismatch1 + " " + mismatch2);‐1 0 ‐1‐1 ‐1 00 ‐1 00 0 ‐1The output is not defined.The code does not compile.

      27 Which line in the main() method doesn't compile or points to a class that doesn't compile?1: interface Comic<C> { 2: void draw(C c); 3: } 4: class ComicClass<C> implements Comic<C> { 5: public void draw(C c) { 6: System.out.println(c); 7: } 8: } 9: class SnoopyClass implements Comic<Snoopy> { 10: public void draw(Snoopy c) { 11: System.out.println(c); 12: } 13: } 14: class SnoopyComic implements Comic<Snoopy> { 15: public void draw(C c) { 16: System.out.println(c); 17: } 18: } 19: public class Snoopy { 20: public static void main(String[] args) { 21: Comic<Snoopy> c1 = c -> System.out.println(c); 22: Comic<Snoopy> c2 = new ComicClass<>(); 23: Comic<Snoopy> c3 = new SnoopyClass(); 24: Comic<Snoopy> c4 = new SnoopyComic(); 25: } 26: }Line 21.Line 22.Line 23.Line 24.None of the above. All of the code compiles.

      28 Fill in the blank to make this code compile:public class Truck implements Comparable<Truck> { private int id; public Truck(int id) { this.id = id; } @Override public int _____________________ { return id - t.id; } }compare(Truck t)compare(Truck t1, Truck t2)compareTo(Truck t)compareTo(Truck t1, Truck t2)None of the above

      29 How many lines does the following code output?var days = new String[] { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" }; for (int i = 0; i < days.length; i++) System.out.println(days[i]);Six.Seven.The code does not compile.The code compiles but throws an exception at runtime.

      30 Which of the following fill in the blank to print out true? (Choose two.)String[] array = {"Natural History", "Science"}; var museums = _______________________; museums.set(0, "Art"); System.out.println(museums.contains("Art"));Arrays.asList(array)Arrays.asList("Natural History, Science")List.of(array)List.of("Natural History", "Science")new ArrayList<String>("Natural History", "Science")new List<String>("Natural History", "Science")

      31 Which option cannot fill in the blank to print Clean socks?class Wash<T> { T item; public void clean(T item) { System.out.println("Clean " + item); } } public class LaundryTime { public static void main(String[] args) { ______________________ wash.clean("socks"); } }var wash = new Wash<String>();var wash = new Wash<>();Wash wash = new Wash();Wash wash = new Wash<String>();Wash<String> wash = new Wash<>();All of these can fill in the blank.

      32 Which of the options in the graphic best represent the blocks variable?char[][] blocks = new char[][] { { 'a', 'b', 'c' }, { 'd' }, { 'e', 'f' } };Option AOption BOption COption D

      33 Fill in the blank so the code prints gamma. (Choose two.)var list = Arrays.asList("alpha", "beta", "gamma"); Collections.sort(list, _______________); System.out.println(list.get(0));(s, t) ‐> s.compareTo(t)(s, t) ‐> t.compareTo(s)Comparator.comparing((String s) ‐> s.charAt(0))Comparator.comparing((String s) ‐> s.charAt(0)).reverse()Comparator.comparing((String s) ‐> s.charAt(0)).reversed()

      34 How many of the following are legal declarations?float[] lion = new float[]; float[] tiger = new float[1]; float[] bear = new[] float; float[] ohMy = new[1] float;NoneOneTwoThreeFour

      35 Which is the first line of code that causes an ArrayIndexOutOfBoundsException?var matrix = new String[1][2]; matrix[0][0] = "Don't think you are, know you are."; // m1 matrix[0][1] = "I'm trying to free your mind Neo"; // m2 matrix[1][0] = "Is all around you "; // m3 matrix[1][1] = "Why oh why didn't I take the BLUE pill?"; // m4m1m2m3m4The code does not compile.None of the above.

      36 Suppose we have list of type List<Integer>. Which method allows you to pass a List and returns an immutable Set containing the same elements?List.copyOf(list)List.of(list)Set.copyOf(list);Set.of(list);None of the above

      37 What does the following output? (Choose two.)var os = new String[] { "Mac", "Linux", "Windows" }; Arrays.sort(os); System.out.println(Arrays.binarySearch(os, "RedHat")); System.out.println(Arrays.binarySearch(os, "Mac"));‐1‐2‐3012

      38 What does the following output?var names = new HashMap<String, String>(); names.put("peter", "pan"); names.put("wendy", "darling"); var first = names.entrySet(); // line x1 System.out.println(first.getKey()); // line x2peterwendyDoes not compile due to line x1Does not compile due to line x2Does not compile due to another reasonThrows an exception at runtime

      39 Which of these elements are in the output of the following? (Choose three.)var q = new ArrayDeque<String>(); q.offerFirst("snowball"); q.offer("sugar"); q.offerLast("minnie"); System.out.println(q.poll()); System.out.println(q.removeFirst()); System.out.println(q.size());sugarminniesnowball123

      40 Which of these four pairs of declarations can point to an array that is different from the others?int[][][][] nums1a, nums1b;int[][][] nums2a[], nums2b;int[][] nums3a[][], nums3b[][];int[] nums4a[][][], numbs4b[][][];

      41 Which of the following does not behave the same way as the others?var set = new HashSet<>();var set = new HashSet<Object>();HashSet<> set = new HashSet<Object>();HashSet<Object> set = new HashSet<>();HashSet<Object> set = new HashSet<Object>();

      42 What is true about the output of the following code?var ints = new int[] {3,1,4}; var others = new int[] {2,7,1,8}; System.out.println(Arrays.compare(ints, others));It is negative because ints has fewer elements.It is 0 because the arrays can't be compared.It is positive because the first element is larger.It is undefined.The code does not compile.

      43 Fill in the blank so the code prints beta.var list = List.of("alpha", "beta", "gamma"); Collections.sort(list, _______________); System.out.println(list.get(0));(s, t) ‐> s.compareTo(t)(s, t) ‐> t.compareTo(s)Comparator.comparing(String::length)Comparator.comparing(String::length).reversed()None of the above

      44 How many of these lines have a compiler error?20: var list = List.of('a', 'c', 'e'); 21: Char letter1 = list.get(0); 22: char letter2 = list.get(0); 23: int letter3 = list.get(0); 24: Integer letter4 = list.get(0); 25: Object letter5 = list.get(0);012345

      45 How many dimensions does the array reference moreBools allow?boolean[][] bools[], moreBools;One dimensionTwo dimensionsThree dimensionsNone of the above

      46 What is the result of the following?Comparator<Integer> c = (x, y) -> y - x;var ints = Arrays.asList(3, 1, 4);Collections.sort(ints, c);System.out.println(Collections.binarySearch(ints, 1));‐10‐1The code does not compile.The result is not defined.

      47 Which statement most accurately represents the relationship between searching and sorting with respect to the Arrays class?If the array is not sorted, calling Arrays.binarySearch() will be accurate, but slower than if it were sorted.The array does not need to be sorted before calling Arrays.binarySearch() to get an accurate result.The array must be sorted before calling Arrays.binarySearch() to get an accurate result.None of the above.

      48 Which statement is true about the following figure while ensuring the code continues to compile? (Choose two.)<> can be inserted at positions P and R without making any other changes.<> can be inserted at positions Q and S without making any other changes.<> can be inserted at all four positions.Both variables point to an ArrayList<String>.Only one variable points to an ArrayList<String>.Neither variable points to an ArrayList<String>.

      49 What is the result of the following when called as java Binary.java? (Choose two.)1: import java.util.*; 2: public class Binary { 3: 4: public static void main(String… args) { 5: Arrays.sort(args); 6: System.out.println(Arrays.toString(args)); 7: System.out.println(args[0]); 8: } }null[]BinaryThe code throws an ArrayIndexOutOfBoundsException.The code throws a NullPointerException.The code does not compile.

      50 What is the first line with a compiler error?class Mammal {} class Bat extends Mammal {} class Cat extends Mammal {} class Sat {} class Fur<? extends Mammal> { // line R void clean() { var bat = new Fur<Bat>(); // line S var cat = new Fur<Cat>(); // line T var sat = new Fur<Sat>(); // line U } }Line RLine SLine TLine UNone


Скачать книгу