These two kinds of initialization seems almost have no difference, after test it myself, what I found about that is only execution sequence distinction.
while new a instance in main method, it will first enter the constructor to create a instance as your order.
At this time, your program will execute the field default value position, which is what you put at RandomClass bar = new RandomClass();
your member field will be filled by the value of default value you have put there.
and this is what we called default value
for member field.
after that sentence, main thread will jump back to the constructor, and execute
bar = new RandomClass();
which means your default setting for a member field will be override by constructor program.
In a conclusion there seems have no too many difference between these two initialization method. and personally speaking, I would like to have a default value for each member field that should have one, or I will have a init()
method in every constructor to unify initialization style .