If I have an abstract class like
public abstract class Player
{
//fields
private Sport _sport;
//properties
protected Sport Sport
{
get { return _sport; }
set { _sport = value; }
}
}
Is this protected access modifier redundant since abstract cannot be instantiated?
No, absolutely not. Consider:
That would be valid if
Sportwere declared as a public property rather than protected. Of course, that may actually be what you want, but currently only code in derived classes (and withinPlayeritself) can access theSportproperty.Note that your entire property would be simpler as an equivalent automatically implemented property though:
Or to allow public getting but protected setting: