Monday, 17 April 2017

How we can Access abstract class function in child class

 Access abstract class function in child class

<?php

abstract class parentTest
{
abstract protected function f1();
abstract public function f2();
public function f4()
{
echo "Parent";
}
}

// Child class ...........
class childTest extends parentTest
{
public function f1()
{
echo "f1";
//body of your function
}
public function f2()
{
parent::f4();//Accessing parent class function
echo ":f2";
//body of your function
}
protected function f3()
{
echo "f3";
        //body of your function
}
}
$a = new childTest();
$a->f2();//Parent:f2

?>

No comments:

Post a Comment