The code in your first example will be converted to code in the second example using the compiler. When you initialize the instance variables where they are defined, it actually moves that initialization to the beginning of the constructor (or some other method immediately before the constructor, which is actually the same).
There are several times when you cannot make the first case (what you assign is too complicated or relies on data that does not yet exist). But other than that, it's just a personal preference. Generally, it is better to avoid mixing the two methods in the same class, although this is a bit more difficult for the reader.
Servy source
share