What is a base class?
A base class is a class in an object-oriented programming language from which other classes are derived. It makes it easier to create other classes that can reuse code implicitly inherited from the base class (other than constructors and destructors). A programmer can extend the functionality of the base class by adding or overwriting elements that are relevant to the derived class.
A base class can also be referred to as a parent class or a super class.
A class derived from a base class inherits both data and behavior. For example, 'vehicle' can be a base class from which 'car' and 'bus' are derived. Cars and buses are both vehicles, but each represents its own specialization of the vehicle class.
A base class has the following properties:
Base classes are automatically instantiated before derived classes.
The derived class can communicate with the base class during instantiation by calling the base class constructor with an appropriate parameter list.
Base class members can be accessed through an explicit cast from the derived class.
If abstract methods are defined in a base class, that class is considered an abstract class and the non-abstract derived class should override those methods.
Abstract base classes are created with the keyword 'abstract' in their declaration and are used to prevent direct initiation with the keyword 'new'.