Question:What is the output of the following script?
<?php

class ClassOne {
  protected $a = 10;

  public function changeValue($b) {
    $this->a = $b;
  }
}

class ClassTwo extends ClassOne {

  protected $b = 10;

  public function changeValue($b) {
    $this->b = 10;
    parent::changeValue($this->a + $this->b);
  }

  public function displayValues() {
    print "a: {$this->a}, b: {$this->b}\n";
  }
}

$obj = new ClassTwo();

$obj->changeValue(20);
$obj->changeValue(10);

$obj->displayValues();

?>
 

A a: 30, b: 30 

B a: 30, b: 20 

C a: 30, b: 10 

D a: 20, b: 20 

E a: 10, b: 10 

+ Answer
+ Report
Total Preview: 921

Copyright © 2024. Powered by Intellect Software Ltd