Is there a difference between the following variable declarations?
Class A {
private int a;
A(){
a= 2;
}
}
VS
Class A {
private int a = 2;
A(){
}
}
Will garbage collection work any differently?
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.
There is no difference in the behaviour of your two initialisations. In the first example the
a = 2will happen just before the constructor code is called. If you madeafinal:Then you would see a difference between what you could do in the constructor: