Interview PHP OOP in PHP

OOP in PHP Questions

1 visible of 2 total
Free Access
Q1
Free (All Users)

What is inheritance in PHP and how does it work?

Inheritance is a fundamental OOP concept where a class (child) can inherit properties and methods from another class (parent) using the extends keyword.

class Animal {
    public string $name;
    public function speak(): string {
        return "...";
    }
}

class Dog extends Animal {
    public function speak(): string {
        return "Woof!";
    }
}

PHP supports single inheritance only – a class can extend only one parent class.

Medium Most Asked Conceptual