The output of this code is:
c: 1 , id: 0
I want to know why the output is not:
c: 0 , id: 1
class A {
private static long c;
private final long id = c++;
public A() {
print("c: " + c + " , id: " + id);
}
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Because an expression like
c++operates like this:c; remember this (e.g.tmp = c😉ctmp)So in this case, you start off with
c = 0, soidbecomes 0… butcis incremented in the process, socis 1 after the expression has been evaluated.See section 15.14.2 of the Java Language Specification for more details. Extract: