PrepAway - Latest Free Exam Questions & Answers

how can we use both traits A and B in the same class?

Given the following code, how can we use both traits A and B in the same class? (select all
that apply) trait A { public function hello() { return “hello”; } public function world() { return
“world”; } } trait B { public function hello() { return “Hello”; } public function person($name) {
return “:$name”; } }

PrepAway - Latest Free Exam Questions & Answers

A.
Rename the A::hello() method to a different name using A::hello as helloA;

B.
Use B::hello() instead of A ‘s version using B::hello insteadof A

C.
Use B::hello() instead of A ‘s version using use B::hello

D.
Rename the A::hello() method to a different name using A::hello renameto helloA;

E.
None of the above (both can be used directly)

Explanation:

One Comment on “how can we use both traits A and B in the same class?

  1. Jare says:

    I believe, the correct answer is A, B.
    1)You can first solve the conflict using option ‘B’ (i.e using insteadof)
    2)Then rename the A::hello as helloA




    1



    0

Leave a Reply

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