ExamGecko
Question list
Search
Search

Question 17 - AD0-E711 discussion

Report
Export

A developer found a bug inside a private method of a third party module class. How can the developer override the method?

A.
Create a custom class with the corrected logic, and define the class as a preference for original one in the di.xml
Answers
A.
Create a custom class with the corrected logic, and define the class as a preference for original one in the di.xml
B.
Create a custom class with corrected logic, and define the class as preference in the preferences.xml.
Answers
B.
Create a custom class with corrected logic, and define the class as preference in the preferences.xml.
C.
Create a plugin, implement correct logic in the 'after' method, and then define the plugin in the di.xml.
Answers
C.
Create a plugin, implement correct logic in the 'after' method, and then define the plugin in the di.xml.
Suggested answer: A

Explanation:

To override a private method of a third-party module class, we need to create our own custom class with correct logic (overridden method) having same name & signature of target method, creating Preference configuration through di.xml that references our new class instead of original one.

Reference: - https://devdocs.magento.com/guides/v2.4/extension-dev-guide/build/di-xmlfile.html#preference-example - https://www.integer-net.com/magento2-overriding-privatemethods/

asked 02/10/2024
Rama Krishna
38 questions
User
Your answer:
0 comments
Sorted by

Leave a comment first