Page 1 of 1
[HD Pg 209, Sec. 8.5.2 - the-default-constructor]
Posted: Mon Feb 18, 2019 6:10 pm
by Username987654
A constructor is provided by you, the programmer,
should be
A non-default constructor is provided by you, the programmer,
?
Re: [HD Pg 209, Sec. 8.5.2 - the-default-constructor]
Posted: Mon Feb 18, 2019 10:46 pm
by admin
I think the statement is fine in that context. The paragraph is driving the point that a constructor does not necessarily have to initialize instance fields. Since, in general, a constructor is coded by the programmer, he/she can choose what to do in the body. The para also includes the statement, " The default constructor provided by the compiler also doesn’t assign any values to the instance members."
Re: [HD Pg 209, Sec. 8.5.2 - the-default-constructor]
Posted: Tue Feb 19, 2019 1:32 am
by Username987654
Understood. Very well done, as always. (It's merely a suggestion to bring perhaps a tiny bit more clarity/precision(?) for that specific statement, particularly for "newbies" that may have to reread it more holistically before comprehending that statement within it's larger point.) Thanks.
Re: [HD Pg 209, Sec. 8.5.2 - the-default-constructor]
Posted: Tue Feb 19, 2019 8:18 am
by admin
sure, will add to todo list.
Re: [HD Pg 209, Sec. 8.5.2 - the-default-constructor]
Posted: Mon Apr 27, 2020 6:02 pm
by addy12345
" if you write any constructor in a class yourself, the compiler will not provide the default constructor at all ". if there is no default constructor ,compiler will fail to compile . In that case how can we create constructors explicitly without causing compile errors?
Re: [HD Pg 209, Sec. 8.5.2 - the-default-constructor]
Posted: Tue Apr 28, 2020 5:34 am
by admin
Where did you read that if there is no default constructor, compiler will fail to compile? Please read Section 8.5.2 from the beginning carefully.
The no-args constructor is required only if you want to use a no-args constructor. It is not necessary for a class to always have this constructor.