Название: OCP Oracle Certified Professional Java SE 11 Developer Practice Tests
Автор: Jeanne Boyarsky
Издательство: John Wiley & Sons Limited
Жанр: Программы
isbn: 9781119696148
isbn:
www.selikoff.net/ocp11-pt
We recommend you read this page before you take the real exam, in case any of the information since the time this book was published has changed. Although less common, Oracle does add, remove, or reword objectives. When this happens, we offer free supplemental material on our website as blog entries.
Ready to Take the Exam
If you can score above 70 percent consistently on all of the chapters related to the exam you want to take, including above a 70 percent on the simulated practice exam, then you are probably ready to take the real exam. Just remember there's a big difference between taking a practice test by yourself in your own home, versus spending hundreds of dollars to take a real proctored exam.
Although a lot of people are inclined to cram as much material as they can in the hours leading up to the exam, most studies have shown that this is a poor test‐taking strategy. The best thing we can recommend that you do before the exam is to get a good night's rest!
Need More Help Preparing?
Both of the authors are moderators at CodeRanch.com
, a very large and active programming forum that is very friendly toward Java beginners. See the OCP Forum.
coderanch.com/f/24
If you don't understand a question, even after reading the explanation, feel free to ask about it in one of those forums. You'll get an answer from a knowledgeable Java programmer. It might even be one of us.
Good luck on the exam and happy studies!
Interactive Online Learning Environment and Test Bank
To access the interactive online learning environment and test bank, simply visit www.wiley.com/go/sybextestprep
, register to receive your unique PIN, and instantly gain one year of FREE access after activation to the interactive test bank with 3 practice exams and hundreds of domain‐by‐domain questions. Over 1,000 questions total!
Chapter 1 Working with Java Data Types
THE OCP EXAM TOPICS COVERED IN THIS PRACTICE TEST INCLUDE THE FOLLOWING:
Working with Java Data TypesUse primitives and wrapper classes, including, operators, parentheses, type promotion and castingHandle text using String and StringBuilder classesUse local variable type inference, including as lambda parameters
1 Which of the following are not valid variable names? (Choose two.)__blue2blueblue$Blue
2 What is the value of tip after executing the following code snippet?int meal = 5; int tip = 2; var total = meal + (meal>6 ? tip++ : tip--);1237None of the above
3 Which is equivalent to var q = 4.0f;?float q = 4.0f;Float q = 4.0f;double q = 4.0f;Double q = 4.0f;Object q = 4.0f;
4 What is the output of the following?12: var b = "12"; 13: b += "3"; 14: b.reverse(); 15: System.out.println(b.toString());12123321The code does not compile.
5 What is the output of the following?5: var line = new StringBuilder("-"); 6: var anotherLine = line.append("-"); 7: System.out.print(line == anotherLine); 8: System.out.print(" "); 9: System.out.print(line.length());false 1false 2true 1true 2It does not compile.
6 Given the following Venn diagram and the boolean variables, apples, oranges, and bananas, which expression most closely represents the filled‐in region of the diagram?apples && oranges && !bananasorange || (oranges && !bananas)(apples || bananas) && orangesoranges && apples(apples || oranges) && !bananasapples ^ oranges
7 What is the output of the following?5: var line = new String("-"); 6: var anotherLine = line.concat("-"); 7: System.out.print(line == anotherLine); 8: System.out.print(" "); 9: System.out.print(line.length());false 1false 2true 1true 2Does not compile
8 Which can fill in the blank? (Choose two.)public void math() { _____ pi = 3.14; }bytedoublefloatshortvar
9 Fill in the blanks: The operators !=, _______, _______, _______, and ++ are listed in the same or increasing level of operator precedence. (Choose two.)==, *, !/, %, **, ‐‐, /!, *, %+=, &&, **, <, /
10 How many of these compile?18: Comparator<String> c1 = (j, k) -> 0; 19: Comparator<String> c2 = (String j, String k) -> 0; 20: Comparator<String> c3 = (var j, String k) -> 0; 21: Comparator<String> c4 = (var j, k) -> 0; 22: Comparator<String> c5 = (var j, var k) -> 0;012345
11 The author of this method forgot to include the data type. Which of the following reference types can best fill in the blank to complete this method?public static void secret(___________ mystery) { char ch = mystery.charAt(3); mystery = mystery.insert(1, "more"); int num = mystery.length(); }StringStringBuilderBothNeither
12 What is the output of the following?var teams = new StringBuilder("333"); teams.append(" 806"); teams.append(" 1601"); System.out.print(teams);333333 806 1601The code compiles but outputs something else.The code does not compile.
13 Which of the following declarations does not compile?double num1, int num2 = 0;int num1, num2;int num1, num2 = 0;int num1 = 0, num2 = 0;All of the aboveNone of the above
14 Given the file Magnet.java shown, which of the marked lines can you independently insert the line var color; into and still have the code compile?// line a1 public class Magnet { // line a2 public void attach() { // line a3 } // line a4 }a2a3a2 and a3a1, a2, a3, and a4None of the above
15 Which is one of the lines output by this code?10: var list = new ArrayList<Integer>(); 11: list.add(10); 12: list.add(9); 13: list.add(8); 14: 15: var num = 9; 16: list.removeIf(x -> {int keep = num; return x != keep;}); 17: System.out.println(list); 18: 19: list.removeIf(x -> {int keep = num; return x == keep;}); 20: System.out.println(list);[][8, 10][8, 9, 10][10, 8]The code does not compile.
16 Which of the following can fill in the blank so the code prints true?var happy = " :) - (: "; var really = happy.trim(); var question = _____________________; System.out.println(really.equals(question));happy.substring(0, happy.length() ‐ 1)happy.substring(0, happy.length())happy.substring(1, happy.length() ‐ 1)happy.substring(1, happy.length())
17 How many of the following lines contain a compiler error?double num1 = 2.718; double num2 = 2._718; double num3 = 2.7_1_8; double num4 = _2.718;01234
18 What is the output of the following application?public class Airplane { static int start = 2; final int end; public Airplane(int x) { x = 4; end = x; } public void fly(int distance) { System.out.print(end-start+" "); System.out.print(distance); } public static void main(String… start) { new Airplane(10).fly(5); } }2 58 56 5The code does not compile.None of the above.
19 What is the output of the following class?1: package rocket; 2: public class Countdown { 3: public static void main(String[] args) { 4: var builder = "54321"; 5: builder = builder.substring(4); 6: System.out.println(builder.charAt(2)); 7: } 8: }234None of the above
20 What is the output СКАЧАТЬ