so a protected member of a base class remains to be protected in a derived class and can therefore be derived again, if i understand this one correctly? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

so a protected member of a base class remains to be protected in a derived class and can therefore be derived again, if i understand this one correctly?

29th Apr 2016, 12:49 PM
Marian Martini
Marian Martini - avatar
6 Answers
+ 2
Yes, that is correct. For example, the following code will work: using System; class A { protected int x=42; } class B : A { } class C : B { public C() { //Access the protected member Console.WriteLine(this.x); } } class Program { static void Main() { C c = new C(); //Outputs 42 } }
20th May 2016, 2:05 PM
James Flanders
0
Yes that's correct.
15th Jun 2016, 12:12 AM
Malachi Jones
Malachi Jones - avatar
0
u can use protected class in other class by determine inheritance "class form : prclass" and u can use protected member in new class this have a diferent with private method
27th Jun 2016, 10:36 AM
Artemis Ariamehr
Artemis Ariamehr - avatar
0
Yes, you are right
5th Jul 2016, 1:47 PM
Kippi
Kippi - avatar
0
Yes you are correct, but can be inherited by another class
27th Jul 2016, 4:20 PM
Markanthony
Markanthony - avatar
0
what is the difference between sealed and private
23rd Aug 2016, 5:01 PM
Harish Elumalai
Harish Elumalai - avatar