How can a derived class call a method from a base class? Other classes should not have access on the other hand.
My situation:
I have a base class, in which I wrote a private method to register some values.
private void register(string param1, int param2){//...}
I did this to allow subclasses to register different stuff. The problem is, that a derived class cannot access private methods or fields of a base class. That makes sense to me, since private means PRIVATE.
I don't want to make the method public because other classes should not be able to call this method.
Can someone provide a solution or guide me towards a better design?
When you declare something private, only the class that defines it can access it. Not even derived classes
What you need is protected
When something is declared as protected
it can be accessed by any derived class while staying hidden from other non-related classes
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With