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 code fragment, when inserted at line 6, enables the code to print true? String str2 = str1; String str2 = new String(str1); String str2 = sb1.toString(); String str2 = "Duke"; 2 / 20 What is returned by the call mystery("java")? "java" "avaj" "jaja" "aaaa" 3 / 20 Which of the following is the output of the code below? double[] myArray = new double[3]; myArray[0] = 2.0; myArray[1] = 4.6; System.out.println(myArray[1] - myArray[2]); 4.6 2.6 -4.6 -2.6 There is an error The code declares an array of three double elements: double[] myArray = new double[3]; In Java, when array elements are not explicitly assigned a value, they are initialized to their default values. The default value for the double primitive type is 0.0. The code explicitly assigns values to the first two elements: myArray[0] is 2.0 myArray[1] is 4.6 myArray[2] remains at its default value, which is 0.0. The System.out.println(myArray[1] - myArray[2]); statement performs a subtraction using these values: 4.6 - 0.0. The result of the subtraction is 4.6 4 / 20 Question 74 47 734 743 347 5 / 20 Which statement about parameters is false? The scope of parameters is the method in which they are defined. Static methods have no implicit parameter this. Two overloaded methods in the same class must have parameters with different names. All parameters in Java are passed by value. Two different constructors in a given class can have the same number of parameters. 6 / 20 Question The relationship between the PlayerGroup and Player classes is an example of: an interface. encapsulation. composition. inheritance. independent classes. 7 / 20 What is the output ? -3 4 5 6 3 4 3 6 5 4 5 6 3 6 4 6 8 / 20 Consider the following class. Which of the following code segments, if placed in a main method in a different class, would cause a compile-time error? Gadget g = new Gadget(5); System.out.println(g.id); System.out.println(Gadget.status); Gadget g = new Gadget(5); All of the above are valid. B: status is a private variable. Even though it is static (meaning it belongs to the class), it cannot be accessed directly from outside the Gadget class. 9 / 20 Question Math.pow returns an int, while Math. sqrt returns a double. x was imprecisely calculated in a previous program statement. The computer stores floating-point numbers with 32-bit words. There is round-oft error in calculating the pow and sqrt functions. There is overflow error in calculating the pow function. 10 / 20 How many times will the word "Hello" be printed? 3 6 9 4 11 / 20 Question I and II are exactly equivalent for all input values n. I and II are exactly equivalent for all input values n ≥ 1, but differ when n≤ 0. I and Il are exactly equivalent only when n = 0. I and I are exactly equivalent only when n is even. I and Il are not equivalent for any input values of n. 12 / 20 Which three statements are true about the structure of a Java class? (Choose three.) A class cannot have the same name as its field. A public class must have a main method. A class can have final static methods. A class can have overloaded private constructors. Fields need to be initialized before use. Methods and fields are optional components of a class. 13 / 20 Question Rational rat (num, denom); rat.reduce(); return rat ; return new Rational (num, denom); reduce(); Rational rat = new Rational (num, denom); return rat; Rational rat = new Rational (num, denom); Rational. reduce(); return rat; Rational rat = new Rational (num, denom); rat.reduce (); return rat ; 14 / 20 What is the output? box nbo nb An exception is thrown at the run time. 15 / 20 For the sample code: Consider this description of the Deck constructor: if (i / 13 == 1) myDeck [i / 13] = new Card("hearts", i % 13); i f (i >= 13 && i <= 25) myDeck [i % 13] = new Card("hearts", i % 13); i f ( i / 13 == 1) myDeck [i] = new Card("hearts", i % 13); i f (i >= 13 && i <= 25) myDeck [i] = new Card("hearts", i / 13); i f (i / 13 == 1) myDeck [i % 13] = new Card("hearts", i % 13); 16 / 20 Question return (int) (getValue() - 0.5); return (int) (getValue() + 0.5); return (int) getValue(); return (double) (getValue() - 0.5); return (double) getValue() ; 17 / 20 Which of the following is equivalent to !(a && b) where a and b are boolean variables? !a && !b !a || !b a || b !(a || b) B: According to De Morgan's Law, when distributing a NOT operator, you negate both variables and flip the operator from AND to OR (or vice versa). 18 / 20 ASCII is a character-encoding scheme that uses a numeric value to represent each character. For example, the uppercase letter "G" is represented by the decimal (base 10) value 71. A partial list of characters and their corresponding ASCII values are shown in the table below. A-65 B-66 C-67 D-68 ASCII characters can also be represented by binary numbers. According to ASCII character encoding, which of the following letters is represented by the 8-bit binary value: 0100 0010 ASCII Character: A ASCII Character: B ASCII Character: D The table does not contain the value represented by the binary number 0100 0010 19 / 20 What is the output? [Robb, Rick, Bran] [Robb, Rick] [Robb, Bran, Rick, Bran] An exception is thrown at runtime. 20 / 20 Question (1) n == 1 && n == 4 (2) k += n (1) n == 1 && n == 4 (2) k += 4 (1) n == 1 || n == 4 (2) k += 4 (1) n == 1 || n == 4 (2) k += n (1) n == 1 || n == 4 (2) k = n - k Your score is 0% Restart quiz