Given the following code, what will the output be:

Given the following code, what will the output be:

trait MyTrait {

}

private $a be = 1;

public function increment() {

$this->abc++;

}

public function getValue() {

return $th is->abc;

class MyClass {

use MyTrait;

public function incrementBy2() {

$th is->i ncre m ent();

$this->abc++;

$c = new MyClass;

$c->incrementBy2();

var_dump($c->getValue());
A . Fatal error: Access to private variable MyTrait::$abc from context MyClass
B . Notice: Undefined property MyClass::$abc
C . int(2)
D . int(3)
E . NULL

Answer: D

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments