Inheritance
class Animal {
public function __construct(
protected string \$name
) { }
public function speak(): string {
return "\$this->name makes a sound";
}
}
class Dog extends Animal {
public function speak(): string {
return "\$this->name barks";
}
}Parent Constructor
class Puppy extends Dog {
public function __construct(string \$name, private int \$age) {
parent::__construct(\$name);
}
}Final Keyword
final class cannot be extended. final method cannot be overridden.
Polymorphism
Objects of different classes can be used interchangeably if they share a parent class or interface.