Junilu Lacar wrote:
Max Ho wrote:so I am wondering why the need to explicitly call super() in the Quantity constructor.
There's no need. If you don't call it explicitly, it will be called implicitly anyway.
Campbell Ritchie wrote:No superclass is named, so the immediate superclass is .....
All Java® programmers should know that.
The details are in the Java™ Language Specification. But it is reluctant to open for me.
Simply: yes. You must initialise all the fields, so as to create your instance in a consistent state, ie fulfilling its class invariants. The only instance where you can get away without a super(...); call is if the superclass has an accessible no-arguments constructor. One must presume that constructor will put the superclass object into a consistent state.
I think the only state in which case it is good design not to initialise the fields in the superclass is when the superclass hasn't got any fields!