Home > Enterprise >  Preventing descendants from overriding method
Preventing descendants from overriding method

Time:03-03

In C (11/14/17, I don't care), I have a base class B which exposes method x as protected.

In class D1, which derives from B, I want to prevent further descendants (of D1) from calling x(). Now, if I were overriding x in D1, I would simply mark it as final.

But, what if D1 does not override x(), yet D1 still wants to hide it from descendants? How can I do that?

CodePudding user response:

How can I do that?

By changing the program and overriding x in D1. You can just delegate to the base class version by calling it.

  • Related