Hi friends,
I want to know Who is a protected class-level variable available to?
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Dhaval PatelRank #1,023 · 1.9K reputationPosted May 29, 2012, 2:18 AM EDT
Protected Class-level varialbe Means,
Access is limited to the containing class or types derived from it
Murad BASDAG23 reputationPosted May 29, 2012, 2:20 AM EDT
For example
class main {
protected int a = 0;
public void SomeMethod()
{
// you can access all public, protected and private members.
}
}
class subclass : main
{
public void SomeOtherMethod()
{
a = 1; // it's legal because it's defined as protected in main class.
// in here you cann't access the private members of the main class.
}
}
I hope this is enough for you.
Satyapriya NayakRank #47 · 31.5K reputationPosted May 29, 2012, 2:27 AM EDT
The protected keyword is a member access modifier. It can only be used in a declaring a function or method not in the class ie. a class can't be declared as protected class.
A protected member is accessible from within the class in which it is declared, and from within any class derived from the class that declare this member. In other words access is limited to within the class definition and any class that inherits from the class
A protected member of a base class is accessible in a derived class only if the access takes place through the derived class type.
Please refer the below link
http://msdn.microsoft.com/en-us/library/bcd5672a(VS.71).aspx
Thanks