Learn AP Comp Sci

Problem of the Day

Wednesday, March 18, 2026


Problem:

The complete listing of the superclass Alpha is given here.

public class Alpha
{
private String a;

public Alpha()
{
a = "a";
}

public String getValue()
{
return a;
}
}

The complete listing of the subclass Beta which inherits from Alpha is given here.

public class Beta extends Alpha
{
public String getValue()
{
return a;
}
}

What is the result of executing the following instructions?

Beta b = new Beta();
System.out.println(b.getValue());
  1. The String "a" is printed
  2. The String "b" is printed
  3. The code compiles but there is a run-time error due to a name collision of the variable a
  4. The code won't compile

(Note: This question includes topics that are not currently part of the AP Computer Science A core curriculum.)

Show solution:

The correct answer is d. The subclass Beta has access to the methods of the superclass, but not to the private instance variables of the superclass. Thus, this code won't even compile.