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

vb.net - Alternative to the T-SQL AS keyword -

php - MySQLi binding parameters in a prepared statement doesn't work unless inserted after "WHERE" -

ios - CFRelease causing crash in iPad application -