I couldn’t understand the need or purpose of “protected” when i have “virtual/override” could someone explain me what do i need those 2 things if they are almost the same.
Edit:
Thanks for all the helpers, i now understand that “protected” is only for visibility purposes, while virtual/override is for class behavior.
They are certainly not almost the same.
The
protectedmodifier sets the visibility of a field or method: such a member can only be accessed from the class it is defined in or from a derived class.The
virtualmodifier specifies that the method it is applied to can beoverriddenin a derived class.These modifiers can be combined: a method can be protected and virtual.