このJavaコードから出力がどのように機能するかを理解したいと思います.親切に助けてください! このコードは、Head First Java という本から引用しました。コードは次のとおりです。
public class EchoTestDrive {
public static void main(String[] args) {
Echo e1 = new Echo();
Echo e2 = new Echo(); // the correct answer
//or
Echo e2 = e1; // is the bonus answer!
int x = 0;
while (x < 4) {
e1.hello();
e1.count = e1.count + 1;
if (x == 3) {
e2.count = e2.count + 1;
}
if (x > 0) {
e2.count = e2.count + e1.count;
}
x = x + 1;
}
System.out.println(e2.count);
}
}
class Echo {
int count = 0;
void hello() {
System.out.println("helloooo... ");
}
}
これは出力です:
%java EchoTestDrive
helloooo...
helloooo...
helloooo...
helloooo...
10