Q: You create a new class by using a method. You need to protect the method from being extended by using Chain of Command (CoC). Which attribute or modifiers should you use to protect the method?
-
A
Use [Hookable(false)] as a method attribute.
-
B
Use [Wrappable(false)] as a method attribute.
-
C
Use [Replaceable(true)] as a method attribute.
-
D
Use a protected modifier.
B
Answer:
B
Explanation:
❌Incorrect. You can use ´[Hookable(false)] to block pre-events and post-events, but it doesn’t block extensions that are made by CoC. To prevent extensions that are made by CoC, use the ´[Wrappable(false)] attribute or the private modifier for the method.
✔️ Correct. ´[Wrappable(false)] generates a compiler error if CoC is your method. In this case, the project isn’t built because a compiler error exists.
✔️ Incorrect. ´[Replaceable(true)] allows you to overwrite the existing method and doesn’t generate a compiler error during build.
Related Topic:
Share Above MCQ