Workbook – Part 4
Prerequisite: you finished writing the code for Part 3.
In this workbook, you will write a copy constructor. The copy constructor copies every value from a
source object into the current object. So, it's our best solution for reference trap 2.
Task 1 – Add a copy constructor
Person class, add a copy constructor.
The copy constructor sets every field in the
current object equal to a value from the
Task 2 – Test the copy constructor
I'm assuming you already created a
Person object. In which case, that person's identical twin is also flying with Java airlines.
Using the copy constructor, set a
person2variable equal to a copy of the first object.
Using the setters, change
seatNumberfields to something else.
Finally, use the same
println()template to print
Name: Rayan Slim Nationality: Canadian Date of Birth: 01/01/1111 Seat Number: 10 Name: Jad Slim Nationality: Canadian Date of Birth: 01/01/1111 Seat Number: 3