conceptoopInheritance allows a class (Child/Subclass) to derive attributes and behavior from another class (Parent/Superclass). It promotes code reuse.
Relationship: “Is-A” (e.g., A Caris aVehicle).
Mechanism: The child gets all public and protected members of the parent.
Examples: Game Entities
C++
Supports Multiple Inheritance (can inherit from many parents).
class Enemy {public: void attack() { cout << "Attacking!"; }};// Orc inherits from Enemyclass Orc : public Enemy {public: void grunt() { cout << "Zug zug"; }};
Java
Supports Single Inheritance (one parent) via extends.
class Enemy { public void attack() { System.out.println("Attacking!"); }}class Orc extends Enemy { public void grunt() { System.out.println("Zug zug"); }}
Rust (No Inheritance)
Rust does not support struct inheritance. Instead, it uses Composition (containing a struct) or Traits (sharing behavior).