PHP program to demonstrate the single inheritance

Here, we are going to demonstrate the single inheritance in PHP.
Submitted by Nidhi, on November 20, 2020

Here, we will implement single inheritance. In the single inheritance, we will inherit the one base class into a single derived class. We will use the extends keyword to implement inheritance.

Program/Source Code:

The source code to demonstrate the single inheritance is given below. The given program is compiled and executed successfully.

//PHP program to demonstrate the single inheritance.
class Base
    function BaseFun()
        echo "BaseFun() called<br>";

class Derived extends Base
    function DerivedFun()
        echo "DerivedFun() called<br>";

$dObj = new Derived();




BaseFun() called
DerivedFun() called


In the above program, we created two classes Base and Derived. Here, we inherited the Base class into the derived class using the extends keyword.

The Base class contains a function BaseFun(), and Derived class also contains only one function DerivedFun().

At last, we created the object $dObj of the derived class. Then called BaseFun() and DerivedFun() using the object that will print the appropriate message on the webpage.

Comments and Discussions

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© some rights reserved.