Is Inheritance supported in PHP?

Questions by shilpak10   answers by shilpak10

Showing Answers 1 - 6 of 6 Answers

manohar

  • May 29th, 2007
 

Yes, Using extends keyword you can extend Superclass.

Ganesh

  • Sep 7th, 2007
 

Yes, Php supports Inheritance.

Lets go for an example,

Class Pay{
      var $Amt=10;
      var $M="";
      Function CheckAmt($Amt){
               $this->Amt=$Amt;
               }
}

Class Salary extends Pay{
      Function CheckAmt($Amt){
        $this->Amt=$Amt;
               If ($this->Amt > 1000){
                  echo "Good Salary";
               } else {
                  echo "Okay Salary";
               }
      }
}
$CheckP = new Pay;
echo $CheckP->Amt;
echo "<br>";
$CheckP->CheckAmt(1000);
echo $CheckP->Amt;
echo "<br>";
$CheckS = new Salary;
echo $CheckS->CheckAmt(100000);

HTH,
Ganes

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions