Skip to main content

Class A in AP Computer Science A

In AP Computer Science A, "Class A" is the conventional placeholder name for a subclass: a Java class declared with `class A extends B` that inherits Class B's public methods and fields while adding (or overriding) its own. It's how the exam tests inheritance without a real-world story.

Verified for the 2027 AP Computer Science A examLast updated June 2026

What is Class A?

"Class A" isn't a special Java feature.

The key idea is the is-a relationship. Every A object is a B, so an A object can go anywhere a B is expected (a B variable, a B parameter, a B array slot). But it doesn't work backwards. A B object is not an A, because A may have extra methods that B knows nothing about. On the exam these stripped-down hierarchies stand in for the named ones you practice with, like Animal -> Mammal -> Dog -> Poodle. If you can trace what A inherits, overrides, and adds, you can handle any hierarchy they throw at you.

Why Class A matters in AP® Computer Science A

The exam loves this setup because it isolates the logic. With no story attached, the only thing being tested is whether you actually understand which class's method runs, which assignments compile, and which casts blow up at runtime.

Is Class A on the AP® Computer Science A exam?

On the multiple-choice section, generic and near-generic hierarchies show up constantly. A classic stem gives you Fruit f = new GrannySmith(); and asks what happens when you call f.polish() or cast f to Apple. The skill is the same either way: trace the hierarchy, know what's inherited, know what runs.

Class A vs Class B (the superclass)

Read it as "A is a B." That means B var = new A(); compiles fine, but A var = new B(); does not, because a plain B object is missing whatever A added.

Key things to remember about Class A

  • In class A extends B, Class A is the subclass and Class B is the superclass, so A inherits all of B's public methods and fields and can add or override its own.

  • An A object can be stored in a B variable (B obj = new A();) because of the is-a relationship, but a B object can never be stored in an A variable.

  • When a method is overridden in A, the object's actual type decides which version runs, even if the variable is declared as type B.

  • The compiler only lets you call methods that exist in the variable's declared type, so calling A-only methods through a B variable won't compile without a cast.

  • Casting a B variable to A only works if the object really is an A (or a subclass of A); otherwise you get a ClassCastException at runtime.

  • Class A's constructor runs B's constructor first via super(), which is why superclass initialization always happens before subclass initialization.

Frequently asked questions about Class A

Does Class A inherit private fields from Class B?

Not directly. Private fields and methods in B exist inside every A object, but A's code can't access them by name.

Will the AP exam actually use classes named A and B?

Sometimes on multiple choice, yes, though named hierarchies like Animal/Dog/Cat or Fruit/Apple/GrannySmith are more common.