method called before super
color created
Constructor of superClass red
Constructor of subClass Green
[OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
~ Mansukh
Manish Dubey J wrote:Does that mean- instance initializer block of superclass("color created") runs 'just' after the statement 'super(getColor)'; completes?
Also please specify whether it is special case of explicit constructor invocation?
~ Mansukh
Mansukhdeep Thind wrote:Hence, this is the compiler's way of ensuring that the developers instantiate the super class before trying to access its fields in sub class.
Manish Dubey J wrote:because the subclass constructor's body gets executed after Instance Initailizer block of superclass but "super();" statement executes before it instance Initialization block.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
~ Mansukh
Winston Gutkowski wrote: why would you be making such a call?
Winston Gutkowski wrote:
PS: You plainly haven't read my StringsAreBad page yet.
Mansukhdeep Thind wrote:
The rule is that the compiler will copy the instance initializer blocks into all the constructors of a class.
Manish Dubey J wrote:It was one useful read.
Thank you!
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here