So in Java, I am confused about this for a long time. When I need an instance in another instance, I have 2 ways:
1.Claim variable a as a member variable, and then instantiate it in constructor: (which is a normal way to do that)
public class ClassA {
SomeType a;
ClassA(){
a = new SomeType();
}
}
2.Directly instantiate it in the member variable definition
public class ClassA {
SomeType a = new SomeType();
}
So is the second one feasible, and why or why not?