PrepAway - Latest Free Exam Questions & Answers

What is the output of the following code?

What is the output of the following code? class A { public $a = 1; public function
__construct($a) { $this->a = $a; } public function mul() { return function($x) { return
$this->a*$x; }; } } $a = new A(2); $a->mul = function($x) { return $x*$x; }; $m = $a->mul();
echo $m(3);

PrepAway - Latest Free Exam Questions & Answers

A.
9

B.
3

C.
6

D.
0

2 Comments on “What is the output of the following code?

  1. Max says:

    code is

    class A
    {
    public $a = 1;
    public function __construct($a) {
    $this->a = $a;
    }
    public function mul() {
    return function($x) {
    return $this->a*$x;
    };
    }
    }

    $a = new A(2);
    $a->mul = function($x) { return $x*$x; };
    $m = $a->mul();
    echo $m(3);




    0



    0

Leave a Reply

Your email address will not be published. Required fields are marked *