Learn AP Comp Sci

Problem of the Day

Friday, June 5, 2026


Problem:

A variable in a computer program has a name and refers to a value. What are the values of variables v1, v2, v3, and v4 after the following code is executed?

int v1;
double v2;
String v3;
boolean v4;

v1v2v3v4
a.00""true
b.00.0""false
c.00.0nullfalse
d.nullnullnullfalse

Show solution:

The correct answer is c. Primitive values such as int, double, and boolean values, if not initialized to some other value when they are declared, have default values of 0, 0.0, and false, respectively. Objects such as instances of the String class, or any other class, have a value of null until they are initialized.