Hi all,

I just started learning Java and I don't understand the output for this particular code and hoping someone could shed some light for me:

class Echo {
int count = 0;
void hello() {
System.out.println("helloooo... ");
}
}


public class EchoTestDrive {

public static void main(String [] args) {
Echo e1 = new Echo();
Echo e2 = new Echo();

e1.count = e1.count + 1;
e2 = e1;

int x = 0;

while ( x < 4 ) {
e1.hello();

if ( x < 4) {
e2.count = e2.count + 1;
}
if ( x == 3) {
e2.count = e2.count + e1.count;
}
x = x + 1;
}
System.out.println(e2.count);
}
}


The output is:

helloooo...
helloooo...
helloooo...
helloooo...
10


But I don't understand how the number is 10 and not 6. From what I read I got the following output:

e1.count = 1
elloooo, helloooo,helloooo,helloooo
e2.count = 5
x = 4

Apologies for such a noobie question but any answer is greatly appreciated.

Thanks in advance