This is a fairly odd question that someone asked me recently and I couldn’t think of a achieve this.
Let Person be a class with several public functions and attributed. Say one of the attributes is color of the eye, with two functions: getColor() and setColor().
Now let Teacher extend to Person to inherit it’s properties.
Her question: What if I don’t want to inherit getColor() and setColor() but the rest of the functions?
My initial thought was to @Override all of them and return void, doing nothing. However, I don’t think this is safe or preferred method, maybe there is a more elegant solution?
That’s essentially the definition of the “contract” of Person, by inheriting from Person, Teacher is “promising” to behave in that way.
Aside from refactoring Person to inherit from, say,
interface PersonBaseandinterface PersonWithEyes, you’re kinda stuck with “doing the right thing” in that context, if you want to present a sane implementation ofPersonto your callers.