I would like to know the difference or impact at any level if we try to initialize a reference declared at class level inside a method. why would we make a reference at class level and initialize it in method scope.
second ques: what about useBox2
please help with technical justification
public class S {
private MyBox b;
public void useBox()
{
b = getBox()
b.abc();
}
public synchronized void useBox2(){
b = newBox();
}
private Box getBox()
{
return new MyBox()
}
}