Single inheritance, a class inherits properties and methods from only one parent class.
<?php
class ParentClass
{
/* Parent class definition */
}
class ChildClass extends ParentClass
{
/* Child class extending ParentClass */
}
?>Example:
<?php
class Person {
public function showName(){
echo "Name: Rahul";
}
}
class Student extends Person {
public function showCourse(){
echo "Course: BCA";
}
}
$obj = new Student();
$obj->showName(); // from parent class
echo "<br>";
$obj->showCourse(); // from child class
?>- Person - Parent class
- Student - Child class
- Student inherits Person using extends
- Child class can use parent methods + its own methods