Possible Duplicate:
Should I initialize variable within constructor or outside constructor
I have here two examples on how to initialize a field (instance variable) in a class. My question is: what's the difference between them? Which one is the best and why?
EXAMPLE 1:
public class Example1 {
private Object field;
public Example1() {
field = new Object();
}
}
EXAMPLE 2:
public class Example2 {
private Object field = new Object();
public Example2() {
}
}