Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using inheritance in constructor (publix X () : y)

I have just seen following code but I do not understand the derivation of base class right in the constructor declaration. What is this and is this possible with ordinal methods?

public SplashAppContext(Form mainForm, Form splashForm) : base(splashForm)
{
this.mainForm = mainForm;
splashTimer.Tick += new EventHandler(SplashTimeUp);
splashTimer.Interval = 2000;
splashTimer.Enabled = true;
}
like image 560
Thomas Avatar asked Dec 01 '22 05:12

Thomas


1 Answers

It's calling a base class constructor, passing the argument splashForm of the type Form to it.

You can call base class methods as well. If you for example have overridden a method which behaviour you want to modify slightly, you do your modifications and call the base class method with base.TheMethod(). This would look like this:

public override void FireMissiles()
{
   PrimeMissiles();

   base.FireMissiles();
}

The syntax for calling a base class constructor and a base class method differs as you can see.

like image 146
Skurmedel Avatar answered Dec 04 '22 20:12

Skurmedel