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());
- The String "a" is printed
- The String "b" is printed
- The code compiles but there is a run-time error due to a name collision of the variable
a - The code won't compile
(Note: This question includes topics that are not currently part of the AP Computer Science A core curriculum.)
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.