← Back to Week 2 Hub
CellPhone Service 3
Overloaded constructors and overloaded methods — multiple ways to create and use objects
Workbook 2a, p.54 — Exercise 3
What You're Building
Add an overloaded constructor to your CellPhone class that accepts all five
properties as parameters. Create a third phone using this new constructor — no setters
needed. Display all three phones and have them dial each other. Optionally, add an overloaded
version of dial() that takes a CellPhone object instead of a phone
number string.
Example Run
Run 1
Phone 1:
Serial Number: 12345
Model: iPhone 15
Carrier: Verizon
Phone Number: 555-123-4567
Owner: Dana
Phone 2:
Serial Number: 98765
Model: Galaxy S24
Carrier: T-Mobile
Phone Number: 855-555-2222
Owner: Marcus
Phone 3:
Serial Number: 55555
Model: Pixel 9
Carrier: AT&T
Phone Number: 333-444-5555
Owner: Lisa
Dana's phone is calling 855-555-2222
Marcus's phone is calling 333-444-5555
Lisa's phone is calling 555-123-4567
Run 2 — With Overloaded dial(CellPhone)
Dana's phone is calling Marcus (855-555-2222)
Marcus's phone is calling Lisa (333-444-5555)
Lisa's phone is calling Dana (555-123-4567)
Key detail: Phone 3 is created using the overloaded constructor — all values are passed in at creation time, so you don't need to call setters afterward.
Concepts You'll Use
This exercise reinforces these concepts from Week 2:
Flow Diagram
Step 1
Add 5-param constructor
All fields as parameters
→
Step 2
Create 3rd phone
Using new constructor
→
Step 3
Display all 3 phones
Using static display()
Step 4
Dial between phones
Each calls another
→
Optional
Overloaded dial()
Takes CellPhone instead of String
Your CellPhone class now has two constructors. Java knows which one to use based on how many arguments you pass.