Back to questions
JuniorTheoryCommon
What does the program print?
var taxi = new Taxi();
class Vehicle { public Vehicle() => Console.Write("V"); }
class Car : Vehicle { public Car() => Console.Write("C"); }
class Taxi : Car { public Taxi() => Console.Write("T"); }VCT
- Expecting
TCV: the object is aTaxi, but each constructor first calls its base one, soVehicleprints first andTaxilast. - Expecting only
Tor a compile error: with no: base(…)written, C# calls the base class's parameterless constructor on its own.
- What changes if
Vehiclehas only the constructorVehicle(string name)? - How would
Taxipass an argument to a constructor ofCar?