Inheritance
Inheritance allows one class to reuse and extend another.
A child class is created using the extends keyword. It automatically inherits all public and protected properties and methods from the parent class.
Private members are not inherited. They remain accessible only inside the class that defines them.
Inheritance is about structural reuse. A parent class defines shared behavior. A child class specializes it.
Protected visibility becomes important here. A protected method cannot be called from outside, but it can be used inside a child class. This allows parents to expose behavior only to subclasses.
Overriding happens when a child class redefines a method with the same name as the parent. The child version replaces the parent version.
The final keyword prevents inheritance or method overriding. It locks structure or behavior to avoid modification.
Inheritance is not just reuse. It defines a relationship: “is a”. A VIPMembership is a Membership. A PremiumAccount is an Account. The child extends the parent, not the other way around.