This age doesn't work for me…

  • 4
  • unavailable
Sometimes we all want to change our age. First, they don't want to sell you cigarettes or beer. Then your hair starts thinning and your back aches! A programmer may not have control over time, but he or she has total control over data in programs. In this task, we correct an error so that a Person object's age variable receives a different value.
You can't complete this task, because you're not signed in.
Comments(20)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
JanuszLevel 9 , Radomsko
28 October, 21:53
It's thanks to the hints of Pushkar Patil
luis_rmrLevel 5 , San Ramon
6 October, 15:03
Two key lecture points to remember in order to resolve this: - An instance variable can't be accessed from static methods - When you declare a variable inside a method, that variable exist only in that method and takes precedence even if there's an instance variable with that name.
QevivLevel 6 , Katowice
28 September, 10:21
After 30 tries i understood >.> wellll
Raj MishraLevel 7 , India
31 August, 13:10
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) { age = age + 20; System.out.println("The age in adjustAge() is " + age); } } } How to meet the last point which is failing?
Clarence L MackeyLevel 4 , Fresno
23 August, 07:23
a bunch of confusing methods and calls that took a looooong time to partially understand. Still, I do appreciate the mental gymnastics and did gain a deeper understanding of calling methods.
Rainer Ricardo RodriguesLevel 4 , Mumbai
26 June, 08:19
Just a small doubt , how to display the runtime screen on the IntelliJ IDE?
Pushkar PatilLevel 6 , Pune
17 June, 11:30
Change variable name e.g adjustAge(int age1){ age = age1 + 20; }
Muhammad VahhaajLevel 19 , Rawalpindi
5 June, 09:44
Just a confusion here, In S.O.P is the age a method variable or instance variable since in age = age + 20 the method variable is used but in S.O.P the field variable is used. Why so? Plz reply if you know
Oleg VanyushkinLevel 18 , St.-Petersburg
15 January, 19:30
Has been thinking on this solution for a while. Nailed eventually. The task idicated lack of my training. Working on it ;)
Vignesh ManoharanLevel 4 , Chennai
15 September 2018, 06:34
The "adjustAge" method should increase the person's age by 20. Try to remember how to call the non-static variable "age" inside the adjustAge method and add 20 to it.