I completed the solution and got all of the conditions. But I fail to understand why the solution is the correct answer. Can anyone explain what is actually happening in the code?
hidden #10587300
Level 14
What's happening here?
Under discussion
Comments (1)
- Popular
- New
- Old
You must be signed in to leave a comment
Attila
29 March 2020, 19:34
The Person class has a field (class variable) :
which is initialized to 20 (when a new object of Person Class is created).
The Person class has a method:
, which takes an int as a parameter.
This method takes the age Field which is created with the current instance of the class:
and adds + 20 to this value.
Now in the main method, as you create a new Instance of the Person Class:
With this you have a new instance of the Person class, called person. This person instance has the int field named age, initialized to 20, which we discussed above. In the method we referred to this variable as:
But from outside of the instance we refer to it as
Now, In this Line:
you call the adjustAge method from the person instance ( person.adjustAge), and we pass the int Field of Person Class as Paramter to it ( person.age), because the method requests an int Parameter.
I hope you understand it this way. If you have not done it, I suggest U install Intelijj with the codegym Plugin, these things will be much more clear using an IDE (in this case Intelijj.) +3