Hi all I have following code that generates error why.If any know please suggest me.
public class Class {
public static void main(String args[]) {
public int i = 10;
i = i++;
System.out.println("Value of i=" + i);
}
}
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.
You’re using a visibility modifier,
public, for a local variable. This isn’t allowed (and makes no sense) since the scope of a local variable is always confined to within that method.The following code:
…compiles no problem.
Note you could also potentially move the
ioutside the method to a field, which would also work:Note that
i = i++may also be causing an issue different to what you’re expecting, but it’s difficult to say without a more thorough explanation. You probably just meanti++on that line.