I got the right answer but I would like it if someone could please break it down for me how the 50 and the 100 are added in the addPrice method. Any help would be greatly appreciated. Thanks.
Breaking it down
Resolved
Comments (4)
- Popular
- New
- Old
You must be signed in to leave a comment
Misiu
28 July 2020, 10:40
Variable "applePrice" is static. Only one variable for all objects Apples.
1. We initialize it with 0; (applePrice = 0;)
2. apple1.addPrice(50); increase it to 50. (Apple.applePrice += applePrice;)
0 + 50 = 50
3. apple2.addPrice(100); increase it to 150. (Apple.applePrice += applePrice;)
50 + 100 = 150
+6
Chris
28 July 2020, 13:48
Thank you so much. That made so much more sense to me now that I look back it. Its just confusing moving back and forth and figuring out the logic. I was thinking 0 = 0 +50 at one point lol.
+1
Misiu
28 July 2020, 14:22
a += 5; means: a = a + 5;
a = 3;
a = a + 4; (or a += 4;)
3 + 4 = 7
and now a = 7
0
Innocent O.
5 September 2020, 09:19
Just a single line of code and i have been sweating for hours! What you dont know; you dont know!
0