AP CSA Unit 3 Day 17: Constructor Default Values

Unit 3, Classes & Objects • Cycle 2
Day 17 Advanced Practice • Harder Difficulty
Focus: Constructor Default Values Hard Constructor Default Values

Advanced Practice Question

Format: Constructor Default Values

What is the output?
public class Item {
    private int quantity;
    private String name;
    
    public Item(String n) {
        name = n;
    }
    
    public int getQuantity() {
        return quantity;
    }
}

// In another class:
Item i = new Item("Pencil");
System.out.println(i.getQuantity());
Difficulty: Hard  |  Topic: Constructor Default Values  |  Cycle: 2 (Advanced)
Why This Answer?

Instance variables have default values. int defaults to 0 since it was never explicitly set in the constructor.

Common Mistake
Watch Out!

Thinking uninitialized instance variables cause errors.

AP Exam Strategy

Instance variables auto-initialize: int=0, double=0.0, boolean=false, objects=null.

Master This Topic

This Cycle 2 HARD question tests constructor default values. Review Unit 3 concepts to build mastery of classes & objects.

  • Understanding constructor default values
  • Tracing code execution accurately
  • Avoiding common pitfalls
View Unit 3 Study Guide

Ready for More Challenges?

Cycle 2 questions prepare you for the hardest AP CSA exam questions.

Study Games Practice FRQs
Back to blog

Leave a comment

Please note, comments need to be approved before they are published.