AP® Computer Science A Multiple Choice Questions
Work through AP Computer Science A multiple-choice questions unit by unit, 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.
Question 1692
Question 1693
Question 1694
Question 1695
Question 1696
Question 1697
public class Account
{
private int id;
private double balance;
private boolean active;
private String owner;
public Account(int theId)
{
id = theId;
}
public String describe()
{
return id + " " + balance + " " + active + " " + owner;
}
}
Consider the following code segment.
Account a = new Account(42);
System.out.println(a.describe());
What is printed when the code segment executes?Main Solution
Answer
Answer: D. Instance variables that are not explicitly initialized take their type's default value: 0 for numeric primitives, false for boolean, and null for reference types including String. The constructor only sets id. So the printed string is "42 0.0 false null". Concatenating null with + produces the literal text "null", not an exception, so option C is incorrect. Option A drops the .0 on a double field; option B treats String default as "" instead of null.
Answer: Correct: D
A
42 0 false
B
42 0.0 false ""
C
A run-time exception will occur because owner is uninitialized.
D
42 0.0 false null
Answer images
Question 1698
Question 1699
Question 1700
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.

