I’m having a conceptual problem here, I have like this:
abstract class A
{ abstract setSomething(bool f1, bool f2);}
class C : A {setSomethng(bool f1, bool f2){/*implementation*/}}
class B : A {setSomething(bool f1, bool f2, bool f3){/*implementation*/} !! ERROR
I’m trying to change the signature of the “setSomething” method in the subClass “B” but it gives me an error that the subClass B doesn’t implement the base abstract class, is there anyway to do this? I mean to overload an inherited abstract method?
When you inherit from an abstract class you either need to provide implementations for all abstract methods, or else you must declare the subclass also as abstract. You are allowed to add new methods, but you can’t remove or change existing methods.
With this in mind you can provide two overloads of the method, one with and one without the extra boolean:
You might even want to consider implementing one in terms of the other:
If you don’t want the two parameter version to be there then you should probably reconsider if it is appropriate to use class A as the base class.