Unit 3 Cycle 2 Day 1: Constructor Overloading
Share
Unit 3, Classes & Objects • Cycle 2
Day 1 Advanced Practice • Harder Difficulty
Focus: Constructor Overloading
Hard
Constructor Overloading
Advanced Practice Question
Format: Constructor Overloading
What is the output?
What is the output?
public class Box {
private int val;
public Box() {
this(10);
}
public Box(int v) {
val = v * 2;
}
public int get() {
return val;
}
}
// In another class:
Box b = new Box();
System.out.println(b.get());
Difficulty: Hard |
Topic: Constructor Overloading |
Cycle: 2 (Advanced)
Why This Answer?
The no-arg constructor calls `this(10)`, which invokes the parameterized constructor with v=10. That constructor sets val = 10 * 2 = 20.
Common Mistake
Watch Out!
Forgetting that this(10) calls the OTHER constructor, not just assigning 10 directly.
AP Exam Strategy
When you see this(...) in a constructor, trace to the constructor it calls.
Master This Topic
This Cycle 2 HARD question tests constructor overloading. Review Unit 3 concepts to build mastery of classes & objects.
- Understanding constructor overloading
- Tracing code execution accurately
- Avoiding common pitfalls
Ready for More Challenges?
Cycle 2 questions prepare you for the hardest AP CSA exam questions.
Study Games Practice FRQs