Home >> PHP >> What is single inheritance in PHP

What is single inheritance in PHP

Single Inheritance:-Inheritance is the process of get or inherit all properties and methods of one class to another class.A child class derived from a single parent class is called single inheritance.
Example:-
Car is derived from vehicle.
Syntax:-

class base{
      //properties
      //methods
}
class derived extends base{
     //properties
      //methods
}
Example:-
class vehicle{
     public function name($string){
            echo "Parent class".$string;
     }
}
class car extends vehicle{
     public function name($string){
            echo "Child class".$string;
     }
}
$vehicle=new vehicle();
$car=new car();
$vehicle->name('of vehicle');
$car->name('of car');

Post Your Comment

Next Questions
What is multiple inheritance
What is multilevel inheritance
How to use static method and property in inheritance
How to use self and parent with static
How to use self and parent without static
What is visibility
What is the difference between public, private, and protected
What is final
What is final class
What is final method
What is final variable
How to print half pyramid using star
How to print half pyramid using number
How to print inverted half pyramid using star
How to print inverted half pyramid using number
How to print half pyramid using one to ten number
How to print pyramid pattern using star
How to print half pyramid pattern using star
How to print half pyramid pattern using star after 180 degree rotation
display errors
string to array
array to string
how to split string into array
How to convert array to string
Difference between exit and die

Copyright ©2022 coderraj.com. All Rights Reserved.