AP® Computer Science A Using Objects and Methods Practice Questions
Work through AP Computer Science A practice questions on Using Objects and Methods, then check each answer against a worked solution.
Free · no sign-up Open questions need no account. Sign up or log in to open the rest.
Subtopic: Using Objects Clear filter
Question 382
Question 383
Question 384
Question 385
String s1 = "AP";
String s2 = s1 + "CSA";
String s3 = "APCSA";
Which of the following statements must be true?Main Solution
Answer
Answer: B. s2 and s3 contain the same characters, so equals returns true. But s2 is produced by concatenating a variable with a literal, so it is not the same reference as s3; therefore s2 == s3 is false.
Answer: Correct: B
A
s2 == s3 is true.
B
s2.equals(s3) is true, but s2 == s3 is false.
C
s1 == s2 and s2 == s3 are both true.
D
s1.equals(s2) is true.
Answer images
Question 386
Question 387
Question 388
Question 389
String s = "computer";
String t = s.substring(0, s.indexOf("u")) + s.substring(5);
What value is stored in t ?Main Solution
Answer
Answer: D. s.indexOf("u") is 4, so s.substring(0, 4) is "comp". Also, s.substring(5) is "ter". Concatenating them gives "compter".
Answer: Correct: D
A
compu
B
comter
C
puter
D
compter
Answer images
AP® and Advanced Placement® are registered trademarks of the College Board, which is not affiliated with, and does not endorse, Verityprep. Names are used for identification purposes only.

