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

Чтение книги онлайн.

Читать онлайн книгу OCP Oracle Certified Professional Java SE 11 Developer Practice Tests - Jeanne Boyarsky страница 29

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

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

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 of the above

      51 What is the result of running the following program?1: package fun; 2: public class Sudoku { 3: static int[][] game = new int[6][6]; 4: 5: public static void main(String[] args) { 6: game[3][3] = 6; 7: Object[] obj = game; 8: obj[3] = "X"; 9: System.out.println(game[3][3]); 10: } 11: }6XThe code does not compile.The code compiles but throws a NullPointerException at runtime.The code compiles but throws a different exception at runtime.

      52 How many of these allow inserting null values: ArrayList, LinkedList, HashSet, and TreeSet?01234

      53 What is the output of the following?var threes = Arrays.asList("3", "three", "THREE"); Collections.sort(threes); System.out.println(threes);[3, three, THREE][3, THREE, three][three, THREE, 3][THREE, three, 3]None of the above

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

      55 What is the output of the following?20: List<Character> chars = new ArrayList<>(); 21: chars.add('a'); 22: chars.add('b'); 23: chars.clear(); 24: chars.remove(0); 25: System.out.print(chars.isEmpty() + " " + chars.length());false 0true 12The code does not compile.The code throws an exception at runtime.

      56 Which fills in the blank in the method signature to allow this code to compile?import java.util.*; public class ExtendingGenerics { private static < ___________, U> U add(T list, U element) { list.add(element); return element; } public static void main(String[] args) { var values = new ArrayList<String>(); add(values, "duck"); add(values, "duck"); add(values, "goose"); System.out.println(values); } }? extends Collection<U>? implements Collection<U>T extends Collection<U>T implements Collection<U>None of the above

      57 What does the following output?String[] os = new String[] { "Mac", "Linux", "Windows" }; System.out.println(Arrays.binarySearch(os, "Linux"));012The output is not defined.

      58 Which is the first line to prevent this code from compiling and running without error?char[][] ticTacToe = new char[3,3]; // r1 ticTacToe[1][3] = 'X'; // r2 ticTacToe[2][2] = 'X'; ticTacToe[3][1] = 'X'; System.out.println(ticTacToe.length + " in a row!"); // r3Line r1Line r2Line r3None of the above

      59 What is the result of the following?var list = new ArrayList<String>(); list.add("Austin"); list.add("Boston"); list.add("San Francisco"); list.removeIf(a -> a.length()> 10); System.out.println(list.size());123None of the above

      60 What happens when calling the following method with a non‐null and non‐empty array?public static void addStationName(String[] names) { names[names.length] = "Times Square"; }It adds an element to the array the value of which is Times Square.It replaces the last element in the array with the value Times Square.It does not compile.It throws an exception.None of the above.

      61 Which is not a true statement about an array?An array expands automatically when it is full.An array is allowed to contain

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