Call to Base constructor
BlitzMax Forums/BlitzMax Beginners Area/Call to Base constructor
| ||
Hey ppl. A little Q. When I have my class inherit from another class and instantiate an instance of it, will the baseclass constructor be called automaticly? And if so, before or after the subclass constructor? If not, can I force a call to it with Super.New() ? Example: Type Base Method New() Print( "Base class Constructor called" ) End Method End Type Type Sub Extends Base Method New() Print( "Sub class Constructor called" ) End Method End Type s:Sub = New Sub I'd expect the output to be either of the following. Possibility A - BAse constructor is ignored. Sub class Constructor called Possibility B - Base constructor is called first Base class Constructor called Sub class Constructor called Possibility C - Sub constructor is called first Sub class Constructor called Base class Constructor called In the case of Possibility A, can I do the following to force a call to the Base constructor? Method New() Print( "Sub class Constructor called" ) Super.New() End Method |
| ||
Morduun was kind enough to compile and run it for me. Turns out Possibility B is the one! Thats good to know. I wont have to worry about not properly instantiated classes. |