Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!

Roman Vilensky

Greenhorn
+ Follow
since Oct 16, 2019
Roman likes ...
Eclipse IDE Java
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
5
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Roman Vilensky

Knute Snortum wrote:[strike]Yeah, my bad

8 months ago

Jeanne Boyarsky wrote:The code you posted isn't the same as the code you tried.



Yeah, I made a mistake somewhere before.
8 months ago
Hello,

So I have the following classes:



And the following code:


When I try to compile, the compiler complains that protectedInt is protected in class Grandpa.

But I'm trying to understand why - Dad is the superclass of Son.
8 months ago

Liutauras Vilda wrote:

Roman Vilensky wrote:Right. I was mistaken about the order in which these happen. I thought it was assign old value, then increment, but it is the other way around.


Unclear whether you understood.

Not sure how that is exactly implemented, but I think always that way.



That's a good point, but in my original example it's not i = n++, it's i = i++.
What I was assuming, is that i gets assigned the old value, but then gets incremented anyway.
What Jeanne Boyarsky pointed out, is that it's a three step process, not a two step process as I assumed. So, not assign old value then increment, but save old value, increment, assign old value.
9 months ago

Campbell Ritchie wrote:Yes, i++ has two values, the value of i (increment) which you cannot see until later, and the old value (remember) which you see now as the value of the whole expression.Many people are surprised when it prints 123.



Right. I was mistaken about the order in which these happen. I thought it was assign old value, then increment, but it is the other way around.
9 months ago

Jeanne Boyarsky wrote:The compiler things about it like this:

  • Ok. So first I execute i++.
  • I'll remember that the original value is 0.
  • Then I'll increment i to 1.
  • Ah, I see you want the result of my statement set to i. No problem, that's the original value you told me to remember.  (zero)
  • Now i is set to 0


  • Oh,

    So that's what I was missing - the "remember" part.
    Instead of my: assign -> increment, it's actually remember-> increment -> assign remembered.

    Thank you!.
    9 months ago
    So I'm going over the OCA book, and in Chapter 2, review question 9, the code is as follows:


    The answer appears to be an infinite loop, because gets assigned the same value every time, and I don't see how:
    If the i is first read and assigned (0), then incremented (1), then at the end of line 2, i = 1.
    If the i is first incremented (1), then assigned (1), then at the end of line 2, i is still = 1.

    So what am I not seeing?

    Thanks.
    9 months ago