package com.codegym.task.task04.task0401;
/*
This age doesn't work for me…
*/
public class Solution {
public static void main(String[] args) {
Person person = new Person();
System.out.println("Age: " + person.age);
person.adjustAge(person.age);
System.out.println("Adjusted age: " + person.age);
}
public static class Person {
public int age = 20;
public void adjustAge(int age) {
this.age =this.age + 20;
System.out.println("The age in adjustAge() is " + age);
}
}
}
that should make how object is working for calling a different function and "this" keyword function pls help me
Under discussion
Comments (5)
- Popular
- New
- Old
You must be signed in to leave a comment
ogniven
25 May 2019, 09:08
this.age = age + 20;
System.out.println("This age is adjustAge() is " + this.age));
0
Roman Gryzin
16 May 2019, 21:28
https://codegym.cc/quests/lectures/questsyntax.level04.lecture01
0
Greg
16 May 2019, 15:41
as i understood non static int can be called with this.age, static can be called with Person.age
May im not right im a beginner as well :)
0
vengadesh
16 May 2019, 11:08
ok pls tell me about difference between static and non-static
0
Greg
16 May 2019, 10:59
this.age = age + 20;
try this it will compile
0