AP CSA 3.4 Exercise 2: Constructors Applied Practice

Unit 3: Class Creation · Lesson 3.4 · Exercise 2

Constructors: Applied Practice

Six scenarios on what a constructor is for, and the one that silently disappears the moment you write your own.

How this one is different

The exercise-1 editor asks you to write constructors. These six ask what an object holds afterward, since the classic constructor bug leaves every field at its default and throws nothing.

Applied Practice

6 questions · scenario driven · every answer is recorded for your teacher

Question 1 of 6Analyze
A class previously had no constructor. A programmer adds one that takes two parameters.
What happens to code that called new MyClass() with no arguments?
Incorrect. The default is withdrawn as soon as any constructor is declared.
Correct. Correct, and the fix is to declare the no-argument constructor explicitly if it is still wanted.
Incorrect. There is no constructor left to call.
Incorrect. Location does not affect which constructors exist.
Question 2 of 6Apply
A constructor takes a parameter named name and the class has a field also named name. The constructor body reads name = name;
What is stored in the field?
Correct. Correct, and this is the silent constructor bug: it compiles, runs, and leaves the object empty.
Incorrect. The assignment is parameter to parameter and has no effect at all.
Incorrect. Self-assignment of a parameter is legal.
Incorrect. That requires this.name on the left.
Question 3 of 6Analyze
A class declares two constructors with different parameter lists.
How does Java decide which one runs?
Incorrect. Parameter count matters only insofar as it matches the call.
Incorrect. Distinct parameter lists are exactly what makes overloading legal.
Incorrect. Declaration order does not select an overload.
Correct. Correct, and it is why two constructors cannot differ by parameter NAMES alone.
Question 4 of 6Apply
A constructor must validate that an age parameter is not negative.
Why is the constructor the right place for that check?
Incorrect. Constructors may call methods freely.
Incorrect. A separate method can be skipped; the constructor cannot.
Correct. Correct. Enforcing an invariant at construction is what keeps it true for the object's whole life.
Incorrect. Speed is not a factor.
Question 5 of 6Evaluate
A programmer writes a method named the same as the class but gives it a void return type.
What have they written?
Incorrect. A constructor has NO return type, not even void. Adding one demotes it to a method.
Correct. Correct, and it is confusing precisely because it compiles.
Incorrect. It is legal, if inadvisable.
Incorrect. A static initializer is a static block with no name.
Question 6 of 6Apply
One constructor needs to do everything another constructor does, plus set one more field.
What is the cleanest approach?
Correct. Correct, and this(...) must be the first statement in the constructor.
Incorrect. Constructors cannot be static.
Incorrect. That creates a second, wasted object and does not initialize this one.
Incorrect. Duplicated setup drifts apart the moment one copy is edited.

Where to go next

Get in Touch

Whether you're a student, parent, or teacher — I'd love to hear from you.

Just want free AP CS resources?

Enter your email below and check the subscribe box — no message needed. Students get daily practice questions and study tips. Teachers get curriculum resources and teaching strategies.

Typically responds within 24 hours

Message Sent!

Thanks for reaching out. I'll get back to you within 24 hours.

🏫 Welcome, fellow educator!

I offer curriculum resources, practice materials, and study guides designed for AP CS teachers. Let me know what you're looking for — whether it's classroom materials, a guest speaker, or Teachers Pay Teachers resources.

Email

[email protected]

📚

Courses

AP CSA, CSP, & Cybersecurity

Response Time

Within 24 hours

Prefer email? Reach me directly at [email protected]