Reference assignment and shared state
📖 Scenario: Imagine you have a simple program that keeps track of a person's name and age using a class. You want to see what happens when you assign one object to another variable and then change the data.
🎯 Goal: You will create a Person class, make two variables that refer to the same object, change the data through one variable, and see how it affects the other.
📋 What You'll Learn
Create a class called
Person with two public fields: Name (string) and Age (int).Create an object of
Person with specific values.Assign this object to another variable to share the reference.
Change the
Age using the second variable.Print the
Name and Age from both variables to show shared state.💡 Why This Matters
🌍 Real World
Understanding reference assignment helps avoid bugs when multiple parts of a program share and modify the same data.
💼 Career
Many programming jobs require knowledge of how objects and references work to write correct and efficient code.
Progress0 / 4 steps