24 Oct 2023




Beginner

Inheritance enables one class to inherit properties and characteristics from another class. The class whose properties and characteristics are inherited is known as the base class or parent class. The class that inherits the properties from the base class is known as the derived class or child class.

Examples:

  1. Basic Example:
    • Class Vehicle has properties like color and speed.
    • Class Car inherits from Vehicle and adds its properties like brand.
  2. Real-world Analogy:
    • Think of inheritance like a family tree; children inherit traits and characteristics from their parents.