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

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


Скачать книгу
History"); museums.add("Science"); museums.add("Art"); museums.remove(2); System.out.println(museums);[Natural History, Science][Natural History, Art, Science]The code does not compile.The code compiles but throws an exception at runtime.

      2 How many of the following are legal declarations?[]String lions = new String[]; String[] tigers = new String[1] {"tiger"}; String bears[] = new String[] {}; String ohMy [] = new String[0] {};NoneOneTwoThreeFour

      3 Which of the following can fill in the blank to make the code compile?public class News<____> {}? onlyN only? and NNews, and ObjectN, News, and ObjectNone of the above

      4 What is true of this code? (Choose two.)26: List<String> strings = new ArrayList<?>(); 27: var ints = new HashSet<Integer>(); 28: Double dbl = 5.0; 29: ints.add(2); 30: ints.add(null);The code compiles as is.One line needs to be removed for the code to compile.Two lines need to be removed for the code to compile.One line of code uses autoboxing.Two lines of code use autoboxing.Three lines of code use autoboxing.

      5 Which of the following creates an empty two‐dimensional array with dimensions 2×2?int[][] blue = new int[2, 2];int[][] blue = new int[2], [2];int[][] blue = new int[2][2];int[][] blue = new int[2 x 2];None of the above

      6 What is the output of the following?var q = new ArrayDeque<String>(); q.offer("snowball"); q.offer("minnie"); q.offer("sugar"); System.out.println(q.peek() + " " + q.peek() + " " + q.size());sugar sugar 3sugar minnie 1snowball minnie 1snowball snowball 3The code does not compile.None of the above.

      7 We are running a library. Patrons select books by name. They get at the back of the checkout line. When they get to the front, they scan the book's ISBN, a unique identification number. The checkout system finds the book based on this number and marks the book as checked out. Of these choices, which data structures best represent the line to check out the book and the book lookup to mark it as checked out, respectively?ArrayList, HashSetArrayList, TreeMapArrayList, TreeSetLinkedList, HashSetLinkedList, TreeMapLinkedList, TreeSet

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

      9 Suppose we want to implement a Comparator<String> so that it sorts the longest strings first. You may assume there are no null values. Which method could implement such a comparator?public int compare(String s1, String s2) { return s1.length() - s2.length(); }public int compare(String s1, String s2) { return s2.length() – s1.length(); }public int compare(Object obj1, Object obj2) { String s1 = (String) obj1; String s2 = (String) obj2; return s1.length() - s2.length(); }public int compare(Object obj1, Object obj2) { String s1 = (String) obj1; String s2 = (String) obj2; return s2.length() – s1.length(); }None of the above

      10 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]);Zero.Six.Seven.The code does not compile.The code compiles but throws an exception at runtime.

      11 Which cannot fill in the blank for this code to compile?var c = new _______________<String>(); c.add("pen"); c.remove("pen"); System.out.println(c.isEmpty());ArrayListLinkedListTreeMapTreeSetAll of these can fill in the blank.

      12 What is true of the following code? (Choose two.)private static void sortAndSearch(String… args) { var one = args[0]; Arrays.sort(args); ________ result = Arrays.binarySearch(args, one); System.out.println(result); } public static void main(String[] args) { sortAndSearch("seed", "flower"); }If the blank contains int, then the code outputs 0.If the blank contains int, then the code outputs 1.If the blank contains int, then the does not compile.If the blank contains String, then the code outputs flower.If the blank contains String, then the code outputs seed.If the blank contains String, then the code does not compile.

      13 How many of the following are legal declarations?public void greek() { [][]String alpha; []String beta; String[][] gamma; String[] delta[]; String epsilon[][]; var[][] zeta; }OneTwoThreeFourFiveSix

      14 What is the result of the following?var list = new ArrayList<Integer>(); list.add(56); list.add(56); list.add(3); var set = new TreeSet<Integer>(list); System.out.print(set.size()); System.out.print(" " ); System.out.print(set.iterator().next());2 32 563 33 56None of the above

      15 What is true of the code when run as java Copier.java? (Choose two.)1: import java.util.Arrays; 2: 3: public class Copier { 4: public static void main(String… original) { 5: String… copy = original; 6: Arrays.linearSort(original); 7: Arrays.search(original, ""); 8: System.out.println(original.size() 9: + " " + original[0]); 10: } 11: } One line contains a compiler error.Two lines contain a compiler error.Three lines contain a compiler error.Four lines contain a compiler error.If the compiler errors were fixed, the code would throw an exception.If the compiler errors were fixed, the code would run successfully.

      16 What is the output of the following? (Choose three.)20: var chars = new _______________<Character>(); 21: chars.add('a'); 22: chars.add(Character.valueOf('b')); 23: chars.set(1, 'c'); 24: chars.remove(0); 25: System.out.print(chars.size() + " " + chars.contains('b'));When inserting ArrayList into the blank, the code prints 1 false.When inserting ArrayList into the blank, the code does not compile.When inserting HashMap into the blank, the code prints 1 false.When inserting HashMap into the blank, the code does not compile.When inserting HashSet into the blank, the code prints 1 false.When inserting HashSet into the blank, the code does not compile.

      17 What is the output of the following?class Magazine { private String name; public Magazine(String name) { this.name = name; } public int compareTo(Magazine m) { return name.compareTo(m.name); } 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()); } }highlightsNewsweeknullThe code does not compile.The code compiles but throws an exception at runtime.

      18 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

      19 What is the first line with a compiler error?class Mammal {} class Bat extends Mammal {} class Cat extends Mammal {} class Sat {} class Fur<T 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

      20 What is a possible result of this code?17: var nums = new HashSet<Long>(); 18: nums.add((long) Math.min(5, 3)); 19: nums.add(Math.round(3.14)); 20: nums.add((long) Math.pow(4,2)); 21: System.out.println(nums);[3][16][16, 3][16, 3, 3]None of the above

      21 What is the output of the following?5: var x = new LinkedList<Integer>(); 6: x.offer(18); 7: x.offer(5); 8: x.push(13); 9: System.out.println(x.poll() + " " + x.poll());13 513 1818 518 13The code does not compile.The code compiles, but prints something else.

      22 Suppose we want to store JellyBean objects. Which of the following require JellyBean to implement the Comparable interface or create a Comparator to add them to the collection? (Choose two.)ArrayListHashMapHashSetSortedArrayTreeMapTreeSet

      23 Which of the following references the first and last elements in a nonempty array?trains[0] and trains[trains.length]trains[0] and trains[trains.length ‐ 1]trains[1] and trains[trains.length]trains[1] and trains[trains.length ‐ 1]None of the above

      24 Which of the following fills in the blank so this code compiles?public static void throwOne(Collection<__________> coll) { var iter = coll.iterator(); if (iter.hasNext()) throw iter.next(); }?? extends RuntimeException? super RuntimeExceptionNone of the above

      25 Which of these four array declarations produces a different array than the others?int[][] nums = new int[2][1];int[] nums[]


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