Название: OCP Oracle Certified Professional Java SE 11 Developer Practice Tests
Автор: Jeanne Boyarsky
Издательство: John Wiley & Sons Limited
Жанр: Программы
isbn: 9781119696148
isbn:
63 Which of the following fills in the blank so this code compiles?public static void getExceptions(Collection<____________> coll) { coll.add(new RuntimeException()); coll.add(new Exception()); }?? extends RuntimeException? super RuntimeExceptionNone of the above
64 What is the output of the following? (Choose two.)35: var mags = new HashMap<String, Integer>(); 36: mags.put("People", 1974); 37: mags.put("Readers Digest", 1922); 38: mags.put("The Economist", 1843); 39: 40: Collection<Integer> years = mags.values(); 41: 42: List<Integer> sorted = new ArrayList<>(years); 43: Collections.sort(sorted); 44: 45: int first = sorted.get(0); 46: System.out.println(first); 47: 48: Integer last = sorted.get(sorted.size()); 49: System.out.println(last);184319221974The code compiles but throws an exception at runtime.
65 How do you access the array element with the value of "z"?dimensions["three"][2]dimensions["three"][3]dimensions[2][2]dimensions[3][3]
66 What is the output of the following?class Magazine implements Comparable<Magazine> { private String name; public Magazine(String name) { this.name = name; } @Override public int compareTo(Magazine m) { return name.compareTo(m.name); } @Override public String toString() { return name; } } public class Newsstand { public static void main(String[] args) { var set = new TreeSet<Magazine>(); set.add(new Magazine("highlights")); set.add(new Magazine("Newsweek")); set.add(new Magazine("highlights")); System.out.println(set.iterator().next()); } }highlightsNewsweekThe code does not compile.The code compiles but throws an exception at runtime.
67 Which options can fill in the blanks to print Cleaned 2 items?import java.util.*; class Wash<T __________ Collection> { T item; public void clean(T items) { System.out.println("Cleaned " + items.size() + " items"); } } public class LaundryTime { public static void main(String[] args) { Wash<List> wash = new Wash<_______________>(); wash.clean(List.of("sock", "tie")); } }extends, ArrayListextends, Listsuper, ArrayListsuper, ListNone of the above
68 How many lines does the following code output?var days = new String[] { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" }; for (int i = 1; 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.
69 What is the output of the following?var listing = new String[][] { { "Book" }, { "Game", "29.99" } }; System.out.println(listing.length + " " + listing[0].length);1 22 12 2The code does not compile.The code compiles but throws an exception at runtime.
70 What is the output of the following?Queue<String> q = new ArrayDeque<>(); q.add("snowball"); q.addLast("sugar"); q.addFirst("minnie"); System.out.println(q.peek() + " " + q.peek() + " " + q.size());sugar sugar 3sugar minnie 1minnie minnie 3minnie snowball 1The code does not compile.None of the above.
71 What is the result of the following?13: var numbers = Arrays.asList(3, 1, 4); 14: numbers.set(1, null); 15: int first = numbers.get(0); 16: int middle = numbers.get(1); 17: int last = numbers.get(3); 18: System.out.println(first + " " + middle + " " + last);The code does not compile.Line 14 throws an exception.Line 15 throws an exception.Line 16 throws an exception.Line 17 throws an exception.3null4
72 Fill in the blank so the code prints gamma.var list = Arrays.asList("alpha", "beta", "gamma"); Collections.sort(list, ___________________________); System.out.println(list.get(0));Comparator.comparing(String::length) .andCompare(s -> s.charAt(0))Comparator.comparing(String::length) .thenCompare(s -> s.charAt(0))Comparator.comparing(String::length) .thenComparing(s -> s.charAt(0))Comparator.comparing(String::length) .andCompare(s -> s.charAt(0)) .reversed()Comparator.comparing(String::length) .thenCompare(s -> s.charAt(0)) .reversed()Comparator.comparing(String::length) .thenComparing(s -> s.charAt(0)) .reversed()
73 What is the output of the following when run as java FirstName Wolfie? (Choose two.)public class FirstName { public static void main(String… names) { System.out.println(names[0]); System.out.println(names[1]); } }FirstNameWolfieThe code throws an ArrayIndexOutOfBoundsException.The code throws a NullPointerException.The code throws a different exception.
74 What does the following output?11: var pennies = new ArrayList<>(); 12: pennies.add(1); 13: pennies.add(2); 14: pennies.add(Integer.valueOf(3)); 15: pennies.add(Integer.valueOf(4)); 16: pennies.remove(2); 17: pennies.remove(Integer.valueOf(1)); 18: System.out.println(pennies);[1, 2][1, 4][2, 4][2, 3][3, 4]The code does not compile.
75 What is true of the following code? (Choose two.)private static void sortAndSearch(String… args) { var one = args[1]; Comparator<String> comp = (x, y) -> _______________; Arrays.sort(args, comp); var result = Arrays.binarySearch(args, one, comp); System.out.println(result); } public static void main(String[] args) { sortAndSearch("seed", "flower"); }If the blank contains ‐x.compareTo(y), then the code outputs 0.If the blank contains ‐x.compareTo(y), then the code outputs ‐1.If the blank contains x.compareTo(y), then the code outputs 0.If the blank contains ‐y.compareTo(x), then the code outputs 0.If the blank contains ‐y.compareTo(x), then the code outputs ‐1.If the blank contains y.compareTo(x), then the code outputs 0.If the blank contains y.compareTo(x), then the code outputs ‐1.
76 What does this code output?String[] nums = new String[] { "1", "9", "10" }; Arrays.sort(nums); System.out.println(Arrays.toString(nums));[1, 9, 10][1, 10, 9][9, 1, 10][9, 10, 1][10, 1, 9][10, 9, 1]
77 Which is the first line to prevent this code from compiling and running without error?char[][] ticTacToe = new char[3][3]; // r1 ticTacToe[0][0] = 'X'; // r2 ticTacToe[1][1] = 'X'; ticTacToe[2][2] = 'X'; System.out.println(ticTacToe.length + " in a row!"); // r3Line r1Line r2Line r3None of the above
78 What is true of the following code? (Choose three.)36: var names = new HashMap<String, String>(); 37: names.put("peter", "pan"); 38: names.put("wendy", "darling"); 39: 40: String w = names.getOrDefault("peter"); 41: String x = names.getOrDefault("peter", "x"); 42: String y = names.getOrDefault("john", "x");One line does not compile.Two lines do not compile.If any lines that do not compile are removed, the String on line 40 is set to null.If any lines that do not compile are removed, the String on line 41 is set to "pan".If any lines that do not compile are removed, the String on line 41 is set to "x".If any lines that do not compile are removed, the String on line 42 is set to "x".
79 What does the following output?18: List<String> list = List.of( 19: "Mary", "had", "a", "little", "lamb"); 20: Set<String> set = new HashSet<>(list); 21: set.addAll(list); 22: for(String sheep : set) 23: if (sheep.length()> 1) 24: set.remove(sheep); 25: System.out.println(set);[a, lamb, had, Mary, little][a][a, a]The code does not compile.The code throws an exception at runtime.
80 Which of the following fills in the blank so this code compiles?public static void getExceptions(Collection<__________> coll) { coll.add(new RuntimeException()); coll.add(new Exception()); }?? extends Exception? super ExceptionNone of the above
Конец ознакомительного фрагмента.
Текст предоставлен ООО «ЛитРес».
Прочитайте эту книгу целиком, купив полную легальную версию на ЛитРес.
Безопасно оплатить книгу можно банковской картой Visa, СКАЧАТЬ