From e2b5b57fa4a4f7803b23a585088c10b8c6d3b995 Mon Sep 17 00:00:00 2001 From: Juuso Rytilahti <rytilahti.juuso@gmail.com> Date: Tue, 30 Apr 2024 10:14:38 +0300 Subject: [PATCH] Updated example --- Part 1.1 - Introduction.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Part 1.1 - Introduction.md b/Part 1.1 - Introduction.md index 78c305d..66da8e3 100644 --- a/Part 1.1 - Introduction.md +++ b/Part 1.1 - Introduction.md @@ -357,11 +357,15 @@ Person person1 = new Person("Alice", 25); Person person2 = person1; // person2 is a reference to the same object as person1 System.out.println("Before change:"); -System.out.println("Person1: " + person1); -System.out.println("Person2: " + person2); +System.out.println("Person1: " + person1); // Person1: Name: Alice, Age: 25 +System.out.println("Person2: " + person2); // Person2: Name: Alice, Age: 25 // Changing person2's name also affects person1 because both reference the same object person2.setName("Bob"); + +System.out.println("After change:"); +System.out.println("Person1: " + person1); // Person1: Name: Bob, Age: 25 +System.out.println("Person2: " + person2); // Person2: Name: Bob, Age: 25 ``` -- GitLab