-2

I am new to C# programming and I have some questions about access modifier protected and private .

Is it true that when data members and member functions of the class are kept "private" ,they can only be accessed by that class and can't even be accessed by the child (derived) class of that class?

In case of protected, if a data members and member functions of that class are kept protected ,then only the code of that class can access those data members and member functions and also if that class has a derived(child ) class ,then even child class can also access the protected data members and member functions of that base (parent ) class ?

Thank

Fahad
  • 41
  • 1
  • 3
  • Have you read https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/access-modifiers ? P.S. Yes you're right about both of them. – ADyson Nov 28 '19 at 17:12

2 Answers2

0

Protected members are accessible by subclasses, private are accessible only in the class

gandalf
  • 451
  • 5
  • 18
0

Well this is going to be a short answer but : yes, this is correct.

Ronan Thibaudau
  • 3,413
  • 3
  • 29
  • 78