java - Initializing Fields Value in Constructor Versus in Fields Declaration -


this question has answer here:

as know, in java , other object-oriented programming languages, fields value can set in constructor or initialized in fields declaration statements. want know essential differences between 2 ways above. , conditions should initialze fields constructor , condtions should't. help.

the advantage argumented constructors can set field values per inputs cant same initialized fields.

so if want create different objects different attribute values go constructors arguements. , assign values of instance variables in constructor.

if want instance variables have default value, assign values @ declaration.


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -