Hi everyone,
So, I solved the problem but I'm having trouble understanding the code. Why do we have to put <this.age = age +20> instead of <person.age = age+ 20>. What does that do?
Explanation?
Under discussion
Comments (3)
- Popular
- New
- Old
You must be signed in to leave a comment
Pavlo Plynko Java Developer at CodeGym
16 April 2020, 08:27
Also, person variable is "visible" in {} brackets where it has been declared only. So if it в was declared in main() method, you can access it in code from declaration until the end of the method.
0
Attila
14 April 2020, 21:40
Person person = new Person();
with this code you create a new instance of the Class Person() and it is name is person.
You can reach the field named age in the Person class through this person instance with
person.age
But when you are writing a code inside the Person class, you refer to the current object (which is not yet created) with the word: this.
this.age
I hope it helped.
+1
Saranya Singh
15 April 2020, 01:32
Ohhh, thank youuu
0