Java Bootcamp Resources, launch
Person class, add a copy constructor.
Your code contains a
Person person = new Person("Rayan Slim", "Canadian", "01/01/1111", 5);
That person's twin is also flying with Java airlines. Use this code to test your copy constructor.
Person twin = new Person(person); // creates a copy of the first object. twin.setName("Jad Slim"); // updates name field of the second object. twin.setSeatNumber(3); // updates the seat number of the second object.
Print the other person's fields as well.
System.out.println("Name: " + twin.getName() + "\n" + "Nationality: " + twin.getNationality() + "\n" + "Date of Birth: " + twin.getDateOfBirth() + "\n" + "Seat Number: " + twin.getSeatNumber() + "\n");
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
Visualizing the Runtime
After you solve this workbook, I still recommend watching the video solution on Udemy.
It will show you how to visualize the runtime using Visual Studio Code.