Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Son.php file
- <?php
- require 'Father.php';
- //include 'Father.php';
- class ChildClass extends ParentClass
- {
- private $sum,$sub,$mult,$div;
- function __construct($num1,$num2){
- $this->sum = $this->add($num1,$num2);
- $this->sub = $this->subtract($num1,$num2);
- $this->mult = $this->multiply($num1,$num2);
- $this->div = $this->divide($num1,$num2);
- }
- public function Display(){
- echo 'Summation is: '. $this->sum.'<br>';
- echo 'Subtract is: '. $this->sub.'<br>';
- echo 'Multiply is: '. $this->mult.'<br>';
- echo 'Division is: '. $this->div.'<br>';
- }
- }
- $myObject = new ChildClass(20,10);
- echo $myObject->Display();
- ?>
- //Father.php file
- <?php
- class ParentClass
- {
- /*private $num1;
- private $num2;*/
- protected function add($num1,$num2){
- /*$this->num1 = $num1;
- $this->num2 = $num2;*/
- return $num1 + $num2;
- }
- protected function subtract($num1,$num2){
- /* $this->num1 = $num1;
- $this->num2 = $num2;*/
- return $num1 - $num2;
- }
- protected function multiply($num1,$num2){
- /* $this->num1 = $num1;
- $this->num2 = $num2;*/
- return $num1 * $num2;
- }
- protected function divide($num1,$num2){
- /*$this->num1 = $num1;
- $this->num2 = $num2;*/
- return $num1 / $num2;
- }
- }
- ?>
RAW Paste Data