PHP program to demonstrate the example of the simple abstract class

Here, we are going to demonstrate the example of the simple abstract class in PHP.
Submitted by Nidhi, on November 21, 2020

Here, we will create an abstract class that contains abstract methods and then inherited the abstract class into a non-abstracted class and definition abstract methods.

Program/Source Code:

The source code to demonstrate the example of a simple abstract class is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.

//PHP program to demonstrate the example of the 
//simple abstract class.
abstract class AbsClass
    public abstract function fun1();
    public abstract function fun2();

class Sample extends AbsClass
    public function fun1()
        printf("fun1() called<br>");
    public function fun2()
        printf("fun2() called<br>");

$obj = new Sample();



fun1() called
fun2() called


In the above program, we created an abstract class AbsClass which contains two abstract functions fun1() and fun2().

After that we created a class Sample, here we used the extends keyword to inherit an abstract class into the non-abstract class, then we defined the functions fun1() and fun2() into the Sample class.

At last, we created the object of the Sample class and called functions 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.