what is difference between following variable usages
public class A{
B b= new B();
public void doSomething()
{
b.callme();
}
}
The REAL difference here is that do you want a different instance of B
each time doSomething
is called? In the second case this is true but it also means that your class is not thread-safe if there are any other methods using B
. And if there are NOT any other methods in the class using B
why not make it a method-scoped variable?