Ken Kallaur

+ Follow
since Jun 28, 2010
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Ken Kallaur

your logic would be correct if name were declared with default access. protected access means that it can be seen within the same package or in any subclass regardless of package, therefore the code does compile.
Thanks guys for the quick replies

I think I'm getting it now.

I had it in my head that

i=i++ would still increment

I understand that
x=i++ equals the old value of i

but my thinking was
i=old value of i now increment i

The thing that throws me off is that where
i does increment
While going through some mock exams I came across the following question in Naveen's test

according to the test the answer is 2, but when I run this in MyEclipse the answer comes back as 0.

if I change the i=i++ to i++ the answer comes out as 2.

I guess my question is does i= in front of the i++ affect the outcome or not?

My thought is that the first time through the loop on the line i=i++ i would be = 0 but the next line i would be incremented to 1 and then similar for the second time through i should be equal to 2