Observing Constructor Flow
On a final note, do know that once a constructor passes arguments to the designated master con-
structor (and that constructor has processed the data), the constructor invoked originally by the
caller will finish executing any remaining code statements. To clarify, update each of the construc-
tors of the Motorcycle class with a fitting call to Console.WriteLine():
class Motorcycle
{
public int driverIntensity;
public string driverName;
// Constructor chaining.
public Motorcycle()
{
Console.WriteLine("In default ctor");
}
public Motorcycle(int intensity)
: this(intensity, "")
{
Console.WriteLine("In ctor taking an int");
}
public Motorcycle(string name)
: this(0, name)
{
Console.WriteLine("In ctor taking a string");
}
// This is the 'master' constructor that does all the real work.
public Motorcycle(int intensity, string name)
{
Do'stlaringiz bilan baham: |