0% 0 votes, 0 avg 28 1234567891011121314151617181920 This quiz randomly generates 20 questions as asked in AP Computer Science A (AP CSA) - Programming in Java. Congratulations! AP Computer Science A (AP CSA) - Programming in Java This quiz randomly generates 20 questions (in 30 mins) as asked in AP Computer Science A (AP CSA) - Programming in Java. 1 / 20 Which of the following expressions is equivalent to !(x < 5 && y >= 10)? x >= 5 || y < 10 x >= 5 && y < 10 x > 5 || y <= 10 x > 5 && y < 10 A: This is De Morgan’s Law. You negate x < 5 (which becomes x >= 5), negate y >= 10 (which becomes y < 10), and change the && to ||. 2 / 20 What is the output? 10 : 30 : 4 10 : 30 : 5 10 : 30 : 6 Compilation Error 3 / 20 What is the output? An exception is thrown at runtime. 07-31-2014 2014-07-31 2014-09-30 4 / 20 What is the length of the myIntegers array initialized in the code below? int a = 8; a *= 2; a = a * 3 / 5; int[] myArray = new int[a]; for(int i = 0; i < myArray.length; i++) { myArray[i] = i % 4; } 8 9 10 16 int a = 8; -> a is 8 a *= 2; -> a is 8 * 2, which is 16 a = a * 3 / 5; -> a is 16 * 3 / 5, which is 48 / 5. In integer division, this results in a being 9. int[] myArray = new int[a]; -> The array myArray is initialized with a length of 9. 5 / 20 What is the output? 2416 0010010016 2216 4416 6 / 20 Variable x of a double type can be to the nearest integer using which statement? (int)x for both positive and negative values of x. (int)(x + 0.5) for both positive and negative values of x. (int)(x + 0.5) for positive values of x, and (int)(x - 0.5) for negative values of x. (int)(x + 1) for both positive and negative values of x. The correct statement to round a double variable x to the nearest integer is (C) (int)(x + 0.5) for positive values of x, and (int)(x - 0.5) for negative values of x. This is because casting to int truncates the decimal part towards zero, and adding or subtracting 0.5 effectively shifts the value so that values halfway or more from zero are then truncated to the next integer away from zero. 7 / 20 What is the output? Nothing is printed An Exception is thrown Compile Error May 15, 2004 8 / 20 Which statement is true about the switch statement? It must contain the default section. The break statement, at the end of each case block, is optional. Its case label literals can be changed at runtime. Its expression must evaluate to a collection of values. The switch statement in Java provides a way to control program flow by executing different blocks of code based on the value of a single expression. It offers an alternative to using multiple if-else if-else statements, often leading to more readable and concise code for handling multiple conditional branches. 9 / 20 What output will be produced by invoking secondTestMethod for a Tester object, assuming that testArray contains 3, 4, 5? 3 4 5 4 5 6 5 6 7 0 0 0 No output will be produced. An ArrayIndexOutDfBoundsException will be thrown. The array will not be changed by the increment method. Nor will the local variable element! What will be changed by increment is the copy of the parameter during each pass through the loop. 10 / 20 What is the output? 4W 100 Auto 4W 150 Manual null 0 Auto 4W 150 Manual Compilation fails only at line n1 Compilation fails only at line n2 Compilation fails at both line n1 and line n2 Java do not allow super() and this() to be called concurrently in the same constructor. super() means calling the constructor from the parent class. this() means calling another constructor within your own class. 11 / 20 Consider the following code segment. What will be printed? 15 12 25 18 A (15): The loop accesses matrix[0][2] (3), matrix[1][1] (5), and matrix[2][0] (7). The sum i 3+5+7=15, 3 plus 5 plus 7 equals 15 3+5+7=15. 12 / 20 What is the output? The sum of dice1 and dice2 No output Error No Double The code simulates rolling two dice and calculates their sum. If the dice values are not equal, it prints the sum. If the sum is 7, it also prints the sum. Otherwise, it prints 'No Double'. 13 / 20 Which of the following are true about arrays? I. All of the elements inside of an array must be of the same type or related types. II. When creating an array with the keyword new, booleans are initialized to True. III. The first element of an array is located at the index of 1. I only II only I and II II and III I, II, and III Statement I is true. Arrays in Java are homogeneous, meaning all elements must be of the same data type or related types (e.g., subclasses of a common parent class or an array of Object can hold different types of objects, but they are all treated as Object references). Statement II is false. When an array of booleans is created using the new keyword, all elements are automatically initialized to their default value, which for booleans is false, not True. Statement III is false. Array indices in Java, and most programming languages, are 0-based. This means the first element of an array is located at the index of 0, not 1. 14 / 20 Question The relationship between the PlayerGroup and Player classes is an example of: an interface. encapsulation. composition. inheritance. independent classes. 15 / 20 In Java, Which of the following data types would NOT be considered a primitive data type? String Boolean Integer Long String is not a primitive data type in Java; it is a reference type (specifically, a class in the java.lang package) used to represent a sequence of characters. Primitive data types are basic types that hold simple values directly in memory and do not have methods associated with them. Java has exactly eight primitive data types: byte, short, int, long, float, double, boolean, and char. 16 / 20 What is the output? [1, 2, 3] [1, 3, 4] [2, 3, 4] Compilation fails [3, 4, null] 17 / 20 What value is stored in result if -5 0 13 -1 12 18 / 20 The +=, -=, *=, /=, and %= operators are known as _______ operators. covalent assignment shorthand assignment compound assignment increment assignment The +=, -=, *=, /=, and %= operators are known as compound assignment or augmented assignment operators, providing a shorthand for performing an arithmetic operation and assigning the result back to the variable (e.g., x += y is x = x + y). 19 / 20 Which three pieces of code, when inserted independently, set the value of amount to 100? At line n1 insert: public CheckingAccount() { amount = 100; } At line n2 insert: this.amount = 100; At line n2 insert: amount = 100; line n1 insert: public CheckingAccount(){ this.amount = 100; } At line n2 insert: acc.amount = 100; At line n1 insert: public CheckingAccount(){ acc.amount = 100; } Option B : this.amount = 100; // ==>Cannot use this in a static context Option C : amount = 100; // ==> Cannot make a static reference to the non-static field amount Option F : acc.amount = 100; // ==> acc cannot be resolved to a variable 20 / 20 Question I only II only I and II only II and III only I and III only Your score is 0% Restart quiz