0% 0 votes, 0 avg 19 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 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. 2 / 20 Which three are advantages of the Java exception mechanism? Improves the program structure because the error handling code is separated from the normal program function? Provides a set of standard exceptions that covers all possible errors Improves the program structure because the programmer can choose where to handle exceptions Improves the program structure because exceptions must be handled in the method in which they occurred Allows the creation of new exceptions that are customized to the particular program being created 3 / 20 What is the output? [Robb, Rick, Bran] [Robb, Rick] [Robb, Bran, Rick, Bran] An exception is thrown at runtime. 4 / 20 What is the output? It results in a compile time error at line n4 It results in a compile time error at lines at lines n1 and n2 It prints : 1 It results in a compile time error at lines at lines n2 and n3 // System.out.println(color); // cannot read the variable, created in the switch block 5 / 20 What is the output? 400 200 200 200 200 200 Compilation fails. 6 / 20 What is the output ? Compilation fails 3 5 0 0 9 25 Class constructor will initialize values of x and y. No problem and easy. 7 / 20 What is the output? c=null b=true f=0.0 c= b=false f=0.0 c=null b=false f=0.0 c=0 b=false f=0.0F 8 / 20 What is the output? Answer = 0 Invalid calculation Compilation fails only at line n1. Compilation fails only at line n2. Compilation fails at line n1 and line2. // ans is initialized in the try-catch block, can not be seen outside the block 9 / 20 What will be the output? True False Compile Error Runtime Error It is Palindrome function. A palindrome program checks if a given input (number or string) reads the same forwards and backward. The core logic involves reversing the input and comparing it to the original. If they match, it's a palindrome; otherwise, it's not. 10 / 20 What is the output? int sum is 30 ; float sum is 30.0 int sum is 30 ; double sum is 30.0 Integer sum is 30 ; double sum is 30.0 Integer sum is 30 ; float sum is 30.0 11 / 20 What is the output? box nbo nb An exception is thrown at the run time. 12 / 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 13 / 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. Four words become HiHowAreYou, since its length is more than 4, nothing will be removed and HiHowAreYou removed will be printed. 14 / 20 What is the output? Compilation fails. The program compiles, but it prints nothing. HiHowAreYou removed An UnsupportedOperationException is thrown at runtime. 15 / 20 What is the output? An exception is thrown at runtime. 07-31-2014 2014-07-31 2014-09-30 16 / 20 What is the output? 1 2 3 0 01 2 3 0 0 An Exception is thrown at run time. 1 2 3 0 01 2 3 1 2 31 2 3 17 / 20 What is the output? 5:5 5:10 10:10 Compilation Fails 18 / 20 What is the output? Vehicle Bus Bus Vehicle Bus The program doesn’t print anything 19 / 20 What is the output? S 6 S 5 S -1 w 7 // no white space before and after "Sweat Sweat", so trim() is not effective // 6th character in str is still S. -- charAt(6) gives S // str.indexOf("Sw", 1); means return the index numver of characters "Sw" but start to count from 1 20 / 20 What is the output? A B A element 0 B element 1 A Null Pointer Exception is thrown at runtime. A 0 B 1 Your score is 0% Restart quiz