# Inheritance and constructor initiation

**URL:** <https://forum.kirupa.com/t/inheritance-and-constructor-initiation/295191>\
**Category:** flash\
**Created:** [August 26, 2009, 1:35pm UTC](https://forum.kirupa.com/t/inheritance-and-constructor-initiation/295191 "2009-08-26T13:35:19Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![nook](https://avatars.discourse-cdn.com/v4/letter/n/90ced4/32.png) [@nook](https://forum.kirupa.com/u/nook)\
**Post date:** [August 26, 2009, 1:35pm UTC](https://forum.kirupa.com/t/inheritance-and-constructor-initiation/295191/1 "2009-08-26T13:35:19Z")

</div>

I have a class **Sub** , that inherits class **Super**.  
In **Super** I have a protected var with default value set that may be overwritten by **Sub** in **Sub’s** constructor.  
(eg _protected var foo:Number = 5_)  
In the constructor of **Super** I want to do a check on that variable overwritten by **Sub**.

First of all, am I right in the assumption that by default, the constructors of the different inherited classes are run in order of: top ancestor \> bottom subclass?

It seems that if I want the subclass constructor to run before the super class I can use the super() method. Is this right?

In my example above I would have to use the super() method in the constructor of \*\*Sub \*\*since I need to set the variable before it is checked in the \*\*Super \*\*constructor.  
But this causes a problem.  
In the \*\*Sub \*\*constructor, if I trace the protected var the output is its native default value (in this case ‘0’) as if it hasn’t been set yet.  
I can change it, and if I trace it again it has the new value.  
But when the \*\*Super \*\*constructor runs after that, the variable is reset to what the \*\*Super \*\*class wanted it to be in the first place (in this case ‘5’).

Can someone please explain the nature of this behaviour?

What would you recommend me to do? Obviously I could move the check to some init handler, but for various reasons I’d like to keep the checking in the constructor.

cheers
