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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Satyapriya NayakPosted May 29, 2012, 6:27 AM
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
Murad BASDAGPosted May 29, 2012, 6:20 AM
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.
Dhaval PatelPosted May 29, 2012, 6:18 AM
Protected Class-level varialbe Means,
Access is limited to the containing class or types derived from it