front 1 Refer to the following method. public static int mystery(int n) What value does mystery(1) return? | back 1 3 |
front 2 If a, b, and c are integers, which of the following conditions is
sufficient to guarantee that the expression evaluates to true? | back 2 a < c |
front 3 When will the result be equal to 3? public static int whatIsIt(int x, int y) return result; | back 3 x <= y |
front 4 What is the output of the following Java code? int x = 0; | back 4 Two Three |
front 5 Consider the method if (s.length() <= 3) else What is the output of | back 5 DELIVER |
front 6 1. Suppose x = 2 and y = 3. If the statement x *= y; is executed once, what is the value of x? A. 2 | back 6 D |
front 7 2. Based on the code below: String sentence; sentence = "Today is Wednesday."; str1 = sentence.substring(9, 18); length1 = sentence.length(); System.out.print(str3); A. To*ay is We*nes*ay. | back 7 A |
front 8 3. Consider the following method definition: public static void printTopHalf() The word static : A. is called the return type | back 8 D |
front 9 4. When you define the procedure, create a ______________ for each value you want to pass into the procedure. A. instance variable | back 9 C |
front 10 5. Look at the following use of the substring() method: String word = "Hello World!"; The String subs will contain: A. "H" | back 10 D |
front 11 6. When defining a function, (unlike a procedure), you must specify a ____________. A. return statement | back 11 D |
front 12 7. Consider the following code segment: if (n != 0 && x / n > 100) If n is of type int and has a value of 0 when the segment is executed, what will happen? A. An ArithmeticException will be thrown. | back 12 D |
front 13 8. Given two strings, a and b, return the result of putting them together in the order abba, e.g. "Hi" and "Bye" returns "HiByeByeHi". || EXAMPLES: public String makeAbba(String a, String b) return result; What would result need to be in order to finish this function? A. a + b + b +a; | back 13 A |
front 14 The elements inside the class body are surrounded with, or delimited
by: | back 14 A |
front 15 In a main method definition, the symbols appearing inside the ( ) are called the: A. getters | back 15 B |
front 16 Which of these words that can appear in a Java program are not a
reserved word? *Hint: It does not show up in blue text in Dr.
Java. | back 16 B |
front 17 Here is a portion of the source code for a computer program: This program is an example of _________________. A. human readable | back 17 B |
front 18 True or False: The following statement, written in the interactions pane, will compile and print to the console. System.out.println("said Sally. "I've said so." See?); | back 18 False |
front 19 Which of these must appear outside the body of a class? A. variable definitions Response Feedback: The import statement cannot go inside the body of the class. Output statements must appear in a method. Comments can appear anywhere. Variable definitions can go inside a method or inside a class. | back 19 C |
front 20 Which of these is a legal (that is, syntactically correct) Java class name? A. U2 Response Feedback: While letters, digits and underscores are legal in identifiers, you cannot start with a digit. You also cannot have spaces or hyphens in an identifier. That leaves U2. | back 20 A |
front 21 Write the main method heading: It must be exactly as Java needs it to be for your code to compile. Hint: *No hint this time. public static void main (String[] args) | back 21 public static void main (String[] args) |
front 22 The following line of code is going to print out what type of value? System.out.print("575"); A. double | back 22 C |
front 23 What is the output of the following code segment? int myAge = 63; int kathysAge = myAge; kathysAge = 60; System.out.print(myAge); A. 63 | back 23 A |
front 24 1. Evaluate the following expression. Make sure that your answer is
correct type. For instance, if the answer is 2 and the type is int,
then you should enter 2. If the answer is 2, and the type is double,
then enter 2.0. | back 24 16.0 |
front 25 2. Evaluate the result from evaluating the following integer
expression. Make sure that your answer is the correct type. For
instance, if the answer is 2 and the type is int, then you should
enter 2. If the answer is 2, and the type is double, then enter
2.0. | back 25 4 |
front 26 3. In the assignment statement below, what is the purpose of the
(double) ? A. To double the amount of the answer, like multiplying by
2. | back 26 B |
front 27 4. Which of the following code fragments will cause an error? | back 27 B |
front 28 5. The statement System.out.print ("No" + (2 + 3) +
"way"); produces the output: | back 28 A |
front 29 6. In Java, Scanner is a class in which package? | back 29 C |
front 30 7. Evaluate the result from evaluating the following integer
expression. Make sure that your answer is the correct type. For
instance, if the answer is 2 and the type is int, then you should
enter 2. If the answer is 2, and the type is double, then enter
2.0. | back 30 8 |
front 31 8. Which of the following statements correctly creates a Scanner
object for keyboard input? | back 31 B |
front 32 9. Which of the following is not a primitive data type? | back 32 B |
front 33 10. What's the result of the following code snippet? | back 33 D |
front 34 1. Refer to the following code fragment: double answer = 12 / 7; The output is The programmer intends the output to be Which of the following replacements for the first line of code will not fix the problem? A. double answer = 12.0 / 7; | back 34 D |
front 35 2. Which one of the following is a correct method of declaring and
initializing an double variable with name crossett? | back 35 C |
front 36 3. The statement System.out.print("No" + "2 + 3"
+ "way"); produces the output: | back 36 B |
front 37 4. What value is stored in result if: int result = 10 - 2 % 2; A. 10 | back 37 A |
front 38 5. True or False: All of the following statements are true. | back 38 True |
front 39 6. Which of the following variable names is an example of a
constant? | back 39 B |
front 40 7. Refer to the following code fragment below: public String yourName = "Kevin"; The name yourName refers to: | back 40 C |
front 41 8. Define: Define Concatenation operator. | back 41 + |
front 42 9. What is the name of the following Scanner object? | back 42 cin |
front 43 10. In a variable definition, the kind of value stored inside is
called its: | back 43 B |
front 44 When a Java string does not have surrounding double quotes, what type of error occurs? | back 44 Compile-time error |
front 45 Text, like everything else in your computer, is stored as raw binary numbers. To treat those numbers as characters, they must be encoded. The encoding scheme used in Java is called: | back 45 Unicode |
front 46 Programs that are designed to "work for you", carrying out a task you specify, are known as | back 46 application programs |
front 47 The devices that feed data and programs into computers are called ______. | back 47 Input Devices |
front 48 If your java source code program compiles, but displays an error message when you run it, then it must have a: | back 48 runtime error |
front 49 What is the computer component that stores program instructions during a program execution? | back 49 memory |
front 50 Four common predefined escape sequences Place a double quote inside a
string: Place a backslash inside a string | back 50 Know the slide 29 on Week 1.2. |
front 51 Each memory cell has a unique location in main memory, called the _________. | back 51 address |
front 52 Which of the following will correctly check to see if the variable x is equal to 5? | back 52 if (x == 5) |
front 53 What is the output of the following code snippet, if the input is 25? public static void main(String[ ] args) { Scanner cin = new Scanner(System.in); System.out.print(“Please enter a number: “); int i = cin.nextInt( ); if(i > 24) { i++; } else { i--; } System.out.println(i); } | back 53 26 |
front 54 What is the output of the following Java code? int x = 0; if(x < 1) System.out.print(“One “); System.out.print(“Two “); System.out.print(“Three”); | back 54 One Two Three |
front 55 What is the value of the price variable after the following code snippet is executed? int price = 42; if(price < 45) { price = price + 10; } if(price < 30) { price = price * 2; } if(price < 100) price = price - 20; } | back 55 32 |
front 56 What is the output of the following code snippet? public static void main(String[ ] args) { int num = 100; if(num != 100) { System.out.println(“Not 100”); } else { System.out.println(“100”); } } | back 56 100 |
front 57 What is the output of the following code snippet? public static void main(String[ ] args) { double income = 45000; double cutoff = 55000; double min_income = 30000; if(min_income > income) { System.out.println(“Minimum income requirements not met.”); } if(cutoff < income) { System.out.println(“Income requirement is met.”); } else { System.out.println(“Maximum income limit is exceeded.”); } } | back 57 Maximum income limit is exceeded. |
front 58 What is the output of the following code snippet? public static void main(String[ ] args) { int s1 = 20; if(s1 < 20) { System.out.print(“1”); } if(s1 <= 40) { System.out.print(“2”); } if(s1 > 20) { System.out.print(“3”); } } | back 58 2 |
front 59 What is the syntax error in the following method definition? public static area(double r) { double a; a = 3.14 * r * r; return r * r; } | back 59 The method does not specify a return type. |
front 60 When you try to convert String data to numeric values, using the Integer.parseInt() or Double.parseDouble() functions on a String that is improperly formatted (containing spaces, commas, or other illegal characters) you will get: | back 60 a NumberFormatException |
front 61 Consider the following method definition: public static void printTopHalf() { } The word printTopHalf : | back 61 is called the method name |
front 62 If you use the String searching functions to search for a particular character or substring, and the value you’re searching for is not found, the methods will return: | back 62 -1 |
front 63 Which of the following represents correct /* implementation */ code for the constructor in the card class? | back 63 mySuit = suit; myValue = value; |
front 64 1. Consider this hierarchy, in which Novel and Textbook are subclasses of Book. Which of the following is a true statement about the classes shown? | back 64 Each of the classes - Book, Novel, and Textbook - can have a method computeShelfLife, whose code in Book and Novel is identical, but different from the code in Textbook. |
front 65 A programmer is designing a program to catalog all books in a library. She plans to have a Book class that stores features of each book: author, title, isOnShelf, and so on, with operations like getAuthor, getTitle, getShelfInfo, and setShelfInfo. Another class, LibraryList, will store an array of Book objects. The LibraryList class will include operations such as listAllBooks, addBook, removeBook, and searchForBook. The programmer plans to implement and test the Book class first, before implementing the LibraryList class. The programmer’s plan to write the Book class first is not an example of | back 65 top-down development. |
front 66 Which statement about the Quadrilateral class is true? | back 66 The perimeter and area methods are abstract because there’s no suitable default code for them. |
front 67 A programmer plans to write a program that simulates a small bingo game (no more than six players). Each player will have a bingo card with 20 numbers from 0 to 90 (no duplicates). Someone will call out numbers one at a time, and each player will cross out a number on his card as it is called. The first player with all the numbers crossed out is the winner. In the simulation, as the game is in progress, each player’s card is displayed on the screen. The programmer envisions a short driver class (sometimes called test class) whose main method has just two statements: BingoGame b = new BingoGame( ); b.playBingo( ); The BingoGame class will have several objects: a Display, a Caller, and a PlayerGroup. The PlayerGroup will have a list of Players, and each Player will have a BingoCard. The relationship between the PlayerGroup and Player classes is an example of | back 67 composition |
front 68 Which statement about the Quadrilateral class is true? | back 68 The method getLabels is wrong and should be getLabels(). |
front 69 Which represents correct /* implementation code */ for the Rectangle constructor? I super(labels, topLeft, botRight); II super(labels); this.myTopLeft = topLeft; this.myBotRight = botRight; III super(labels); myTopLeft = topLeft; myBotRight = botRight; | back 69 II and III only |
front 70 Consider an ArrayList<Quadrilateral> quadList whose elements are of type Rectangle, Parallelogram, or Square. Refer to the following method, writeAreas: What is the effect of executing this method? | back 70 The appropriate area method for each quad in quadList will be determined. |
front 71 Refer to the definitions of ClassOne and ClassTwo below. Consider the following declarations in a client class. You may assume that ClassOne and ClassTwo have default constructors. ClassOne c1 = new ClassOne(); ClassTwo c2 = new ClassTwo(); Which of the following method calls will cause an error? I. c1.methodTwo(); II. c2.methodTwo(); III. c2.methodOne(); | back 71 I only |
front 72 Which of the following will execute without throwing an exception? I. String s = null; String t = ""; if (s.equals(t)) System.out.println("empty strings?"); II. String s = "holy"; String t = "moly"; if (s.equals(t)) System.out.println("holy moly!"); III. String s = "holy" String t = s.substring(5); System.out.println(s + t); | back 72 II only |
front 73 A programmer plans to write a program that simulates a small bingo game (no more than six players). Each player will call out numbers one at a time, and each player will cross out a number on his card at it is called. The first player with all the numbers crossed out is the winner. In the simulation, as the game is in progress, each player's card is displayed on the screen. The programmer envisions a short driver class whose main method has just two statements: BingoGame b = new BingoGame(); b.playBingo(); The BingoGame class will have several objects: a display, a Caller, and a PlayerGroup. The PlayerGroup will have a list of Players, and each Player will have a BingoCard. The relationship between the PlayerGroup and Player classes is an example of | back 73 composition. |
front 74 Which of the following correctly initializes an array arr to contain four elements each with value 0? I. int[] arr = {0, 0, 0, 0}; II int[] arr = new int[3]; III int[] arr = new int [4]; for (int i = 0; i < arr.length; i++) arr[i] = 0; | back 74 I and III only |
front 75 Consider the following method. public static int mystery(int[] arr) { int x = 0; for (int k = 0; k < arr.length; k = k + 3) x = x + arr[k]; return x; } Assume that the array nums has been declared and initialized as follows. int[] nums = {3, 6, 1, 0, 4, 1, 2}; What value will be returned as a result of the call mystery(nums) ? | back 75 5 |
front 76 Consider the following method. public ArrayList<Integer> mystery(int n) { ArrayList<Integer> seq = new ArrayList<Integer>(); for (int k = 0; k <= n; k++) seq.add(new Integer(k * k + 3)); return seq; } Which of the following is printed as a result of executing the following statement? System.out.println(mystery(6)); | back 76 [3, 4, 7, 12, 19, 28, 39] |
front 77 Consider the following code segment. int x = 7; double y = 3; if ((x < 10) && (y < 0)) System.out.println("Value is: " + x * y); else System.out.println("Value is: " + x / y); What is printed as a result of executing the code segment? | back 77 Value is: 2.3333333 |