It was quite easy to find the right solution, but I didn't understand why it was the right answer?
tache résolu mais pas comprise
Résolues
Commentaires (1)
- Populaires
- Nouveau
- Anciennes
Tu dois être connecté(e) pour laisser un commentaire
Gellert Varga
6 septembre 2021, 19:32solution
I.) You cannot access the instance variable of an object this way:
but only this way:
somethingObject.A = 15;
But in main() we can see this:
A = 15;
so on that basis, 'A' is guaranteed have to be static (=can't be an instance variable.)
II.)
If 'C' would be static, then 'A' and 'B' should also be static. Because with a static variable you cannot access instance variables , only other static variables.
But then we already would have 3 static variables...
If 'C' is not static (= instance variable), then 'C' can access other non-static variables (for example 'B'), since they are inside the same object.
But 'C' can also access static variables (for example 'A'), because static = common, so all objects can use them in common.
So in this code line you can use both 'A' and 'B', even though 'B' is an instance variable and 'A' is a static one. +2