What keyword would you use to hide a member of a base class?

Prepare for the MTA Software Development Fundamentals Exam! Access flashcards, multiple-choice questions, and detailed explanations to enhance your learning and ace your exam.

To hide a member of a base class in object-oriented programming, specifically in C#, the "new" keyword is used. This keyword indicates that a derived class member is intentionally hiding a member inherited from the base class. By using "new", the derived class can define its own version of a member (method, property, etc.) that has the same name as the base class member, leading to the new member being used rather than the one in the base class when accessed through the derived class.

When a member is hidden using the "new" keyword, it is important to note that the original member in the base class still exists and will be available when accessed from an instance of the base class or when referenced through a base class type. This allows for flexibility in design, enabling the derived class to provide a different implementation while still maintaining access to the base class functionality if needed.

The other keywords—protected, virtual, and sealed—have different purposes. "Protected" limits access to a member to the defining class and its derived classes, without hiding it. "Virtual" allows a method to be overridden in a derived class, maintaining polymorphic behavior instead of hiding. "Sealed" prevents further derivation of a class and prohibits overriding any

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy