Because the initial values apply to every instance of a Person, not just to the one you are talking about.
If you change the initial value to "Jones" then it would work fine - until you tried to add a second person "Smith".
The initial value is a "default placeholder" and is created as part of the "setup" of a Person rather than as part of an individual human being. It doesn't create anything that relates to any individual, it just sets up the framework for an individual to be recorded in.
When you do this:
var firstPerson = Person()
You are creating an indiviidual, and you then fill in his details:
var firstPerson = Person()
firstPerson.Name = "Jones"
You can also create a different person:
var firstPerson = Person()
firstPerson.Name = "Jones"
var secondPerson = Person()
firstPerson.Name = "Smith"
Andthe two names are independant of each other, as you would expect in the real world.
If you assign names by creating a new variable (firstPerson, secondPerson etc.) why do you need to put .Name at all? Why can't you just write:
firstPerson = "Jones"
secondPerson = "Smith"
You could...but then the name wouldn't have any related info which is held in the Person class: Age, Address, JobTitle, or whatever.
Let's just think about cars for a moment: Here is a car, it's a Red Mercedes. It's My Car. Over there is a different car: a Blue Ford. That is Your Car.
They two are not the same object - if you put your mobile in the glove box of Your Car you don't expect to find it in the glove box of My Car - but they have a lot of info associated with them: engine size, fuel type, number of doors, model, age, registration number, VIN number, ... the list goes on. To represent that in a computer, you could just have separate variables for each attribute, but then you'd need a couple of dozen variables for My Car, and a separate couple of dozen for Your Car - and if we introduce That Car, This Car, His Car, Joes Car if makes the code very unwieldy.
So we create a Car class which holds all the related information about a single vehicle and fill in the information for each car to keep it all together (this is called an
instance of the Car class to separate it from the
definition of the class)
Now when we talk about My Car we can look at the class instance and we can get the Colour, engine size, left or right hand drive, wheel size, or whatever we need at that point for that one specific vehicle.
The other thing we can do is play around with it: we don't need to know whose car it is in order to do things with it. What I mean by that is that the name of the variable (in your case
firstPerson
) has nothing to do with the instance of the class that it contains - this is stuff your tutor will bring up later, but because the variable isn't the instance but just a reference to it you can pass the reference to a function which doesn't need to know where the instance came from, it just processes any instance.
That's probably not clear at the moment - and I don't want to tread on your tutors toes too much here - but if we go back to cars for a moment, MyCar is a variable which refers to a specific vehicle. But MyWifesCar is another variable which refers to the same vehicle, as is ThisCar, and OurCar - the individual names aren't the object itself because if something changes in the actual vehicle (I drive it into a tree perhaps) then the damage is reflected in the vehicle, regardless of which variable I use to access it: MyCar, ThisCar, OurCar, MyWifesCar all refer to the same instance of a vehicle.
You can't do that with separate variables! :laugh:
Does that make any sense?