I just solved this puzzle but without understanding it. I started with a Chat.name that didn't work but this.name did, Why?
Why This ?
Discussion en cours
Commentaires (2)
- Populaires
- Nouveau
- Anciennes
Tu dois être connecté(e) pour laisser un commentaire
Gellert Varga
4 septembre 2021, 17:30
The static variable belongs to the class only. It is not part of any object.
If the variable 'name' in the task were static, it would be referred to as Chat.name.
Static variable is shared by all objects. There is only one "instance" of a static variable.
Study this program and the output:
OUTPUT:
Lily
Lily
Lily
Lily
All objects have access to this common variable, so you can also refer to it like this:
this.name
and also like this:
Chat.name
But in the task you are asking about, the name variable is NOT STATIC, it is an instance variable. Each object will have an OWN 'NAME', with different string value.
Therefore, 'Chat.name' formula does not exist in that program.
(The Chat.name would be a static 'name' variable, but there is not any static 'name' variable in that program.) 0
VertOursReturn
4 septembre 2021, 17:52
thanks for your explications
0