I have the following code snippet:
public abstract class Foo
{
protected Foo()
}
Is there any difference in inheritance between using protected as the access modifier or public?
I´ve mostly seen using protected in this case. So there is the difference and why do people use proteced over public?
There may be some subtle situations where it would make a difference (and it would be detectable with reflection) but essentially they're the same. It's probably clearer to make it protected
, as it can't actually be called other than by a constructor of a derived class.
One difference is if you plan on serializing the class, then you must have a default public
constructor (default meaning the constructor takes no arguments). Otherwise, like Jon says the difference is slight.
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