Je ne comprend vraiment rien a la solution. Déja pourquoi il n y a pas le this. devant le nom puisque c' est une variable non statique? 2 pourquoi l on crée un nouvel objet couleur dans le constructeur Cercle? Le constructeur est fait pour initialiser un objet et pour donner ou pas une valeur aux variables d instances. Mais la on ne donne pas de valeur a couleur, on crée juste un objet couleur. Quelqu un peut m aider a comprendre. Merci :)
david
Niveau 10
Je ne comprend pas du tout cette solution.
Discussion en cours
Commentaires (2)
- Populaires
- Nouveau
- Anciennes
Tu dois être connecté(e) pour laisser un commentaire
Guadalupe Gagnon
30 décembre 2020, 21:33utile
The 'this' keyword is only needed in 2 cases:
1) when there is a class field and a local variable that have the same exact name, creating a conflict in the names (which one do you mean when you use the name?):
and 2) when referring to the current object, which is an advanced topic at this point which you will learn about later and I won't go into more detail here.
To make the Circle class valid all the fields that are part of the class need to be initialized. The Circle class has one class field that is a Color. As you say: the constructors job is to make the current object valid, which is correct. So, it has to create a new Color to properly initialize that field of the Circle and make it valid a valid object. +2
david
31 décembre 2020, 10:45
Merci c 'est un peu plus clair :)
0