Junior OOP

What is the : base() keyword used for?

  • Calls the constructor of the base class from a derived class.
  • Ensures base class initialization before derived class constructor runs.

class Vehicle { public Vehicle(string brand) {

Console.WriteLine(brand); } }

class Car : Vehicle

public Car(string brand) : base(brand) { Console.WriteLine("Car

created"); }

More from C# Programming Tutorial

All questions for this course