Java Bootcamp – Workbooks and Challenges
)}

Workbook 7.4

From the Java Bootcamp Resources, launch Workbook 7.4.

4.png

Task 1

Inside the Person class, add a copy constructor.

Task 2

Your code contains a Person object.

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.

4.png

It will show you how to visualize the runtime using Visual Studio Code.


Associated Course: The Complete Java Development Bootcamp
Related Course: The Complete Spring Boot Development Bootcamp – Become a Java Web Developer

Feedback Summary
4.7
43 students
5

91%
4

2%
3

0%
2

0%
1

7%
Written Reviews
There are no written reviews yet.