This site requires JavaScript, please enable it in your browser!
Greenfoot back
LegendXV
LegendXV wrote ...

2014/5/2

Inheritance Question

LegendXV LegendXV

2014/5/2

#
If I've got this inheritance hierarchy ... Person -> Toddler -> Teenager -> Adult (Toddler extends Person, Teenager extends Toddler, Adult extends Teenager) and Adult calls the super() constructor in its code, does it reference the Teenager class, or the Person class.
danpost danpost

2014/5/3

#
Ok. The easiest way to explain this is as follows; (a) yes, a toddler is a person (b) no, a teenager is NOT a toddler (c) no, an adult is NOT a teenager For (b) and (c) (b) yes, a teenager is a person (c) yes, an adult is a person From this, if 'yes', then it can be an extension of what it is; if 'no', then it cannot.
davmac davmac

2014/5/3

#
I think your inheritance hierarchy looks incorrect, as danpost says. To answer the question though, assuming you are using that hierarchy, calling the super() constructor from Adult calls the constructor of the immediate superclass, which is Teenager. However, this constructor will then also generally call the constructor of its own immediate superclass and so on.
You need to login to post a reply.