Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


Explain about Protected and protected internal, ?internal?
access-specifier?

Answers were Sorted based on User's Feedback



Explain about Protected and protected internal, ?internal? access-specifier?..

Answer / ranganathkini

Protected access specifier implies that the class member is
accessible to other members of the same class or to members
of a class that derieves from the class the member
originates from. example:

namespace Ranga.AccessTest {
class ClassA {
protected void MethodA() {

}
}

class ClassB : ClassA {
public void MethodB() {
base.MethodA(); // invoke MethodA()
}
}

class ClassC {
public void MethodC() {
// ClassC is not subclass of ClassA
// Hence it cannot access MethodA
ClassA myA = new ClassA();
myA.MethodA(); // ERROR
}
}
}

Protected internal access-specifier implies that the class
member is accessible in its originating class as well as
other class in the same assembly (i.e. EXE or DLL ). This
means that the member's access is protected OR internal.
Example.

// The foll. classes will be compiled into Program1.dll
namespace Ranga.Program1 {
public class ClassA {
protected internal void MethodA() {

}
}

public class ClassB : ClassA {
public void MethodB() {
base.MethodA(); // invoke MethodA()
}
}

public class ClassC {
public void MethodC() {
// Since ClassC is now in the same assembly
// as ClassA, MethodA is now accessible to it
// as it is marked as protected OR internal
ClassA myA = new ClassA();
myA.MethodA(); // NO ERROR HERE
}
}
}

// The foll. classes will be compiled into Program2.exe
// add reference to Program1.dll while compiling
using Ranga.Program1;

namespace Ranga.Program2 {
class ClassD {
public void SomeMethod1() {
// ERROR because ClassD is not in the same
// assembly as ClassA, MethodA is not accessible
// to it.
ClassA myA = new ClassA();
myA.MethodA(); // ERROR
}
}

// Now observe this
class ClassE : ClassA {
public void SomeMethod2() {
// We can call MethodA of ClassA here
// though ClassE is in a different assembly
// it is a derieved class of ClassA, hence
// MethodA() becomes accessible to it.
base.MethodA() // NO ERROR HERE
}
}
}

Hope it helps!!!

Is This Answer Correct ?    52 Yes 4 No

Explain about Protected and protected internal, ?internal? access-specifier?..

Answer / diana cheriyan

Protected:-Access is limited to the Containing class or
types derived from the Containing class

Internal:-Access is limited to the Current Assembly

Protected Internal:-Access is limited to the current
Assembly or types derived from the Containing class

Is This Answer Correct ?    19 Yes 7 No

Explain about Protected and protected internal, ?internal? access-specifier?..

Answer / sumathi

Protectd :

Method declared as Protected,means it is accessible only in
it's derived classes.
So with this access specifier we can provide more security
to the class members.

Protected internal:

Methods or varibales are declared as protected internal are
accessible in the derived classes but outside the assembly
also.

Internal:
Member Methods or member variables declared as internal are
accessible with in classes of the same assembly.

Is This Answer Correct ?    14 Yes 4 No

Explain about Protected and protected internal, ?internal? access-specifier?..

Answer / sudhir kumar

Protected access specifier allows a class to hide its member
variables and member functions from other class objects and
functions, except the child class.
The protected access specifier becomes important while
implementing inheritance.
Protected members are not Visible to objects of other class,
or other classes outside the namespace collection,and also
not visible to objects of child classes outside the
namespace collection.


Protected access specifier allows a class to hide its member
variables and member functions from other class objects and
functions, except the child class,with in the application.
The protected access specifier becomes important while
implementing inheritance.
Protected members are not Visible to objects of other class,
or other classes outside the namespace collection,and also
not visible to objects of child classes outside the
namespace collection.

Is This Answer Correct ?    6 Yes 4 No

Explain about Protected and protected internal, ?internal? access-specifier?..

Answer / sainath

Mr.Ranganathkini,
Your explanation helped me a lot,
I need some more clarification.
suppose in your first example Class C is in namespace
Ranga.AccessTest , if it was not in the same namespace, but
let us assume that it has inherited the class A, then could
it have the access to methodA.

Is This Answer Correct ?    3 Yes 2 No

Explain about Protected and protected internal, ?internal? access-specifier?..

Answer / krishna

Iam agree with Ranganathkini answer

Is This Answer Correct ?    1 Yes 16 No

Explain about Protected and protected internal, ?internal? access-specifier?..

Answer / sriram

I Know but I will not tell

Is This Answer Correct ?    6 Yes 25 No

Post New Answer

More C Sharp Interview Questions

How to reduce image resolution in C#?

0 Answers   IBM,


What is overloading and how can this be done ?

4 Answers   MMTS,


What is signature c#?

0 Answers  


What is marker interface?

1 Answers   TCS,


What is the difference between ienumerable and enumerable?

0 Answers  


How do destructors and garbage collection work in c#?

0 Answers  


What is the c# equivalent of c++ catch (...), Which was a catch-all statement for any possible exception?

0 Answers  


What is the predicate of a sentence?

0 Answers  


How can we set class to be inherited, but prevent the method from being over-ridden?

0 Answers  


What is entity framework c#?

0 Answers  


What is the difference between a field and a property in c#?

0 Answers  


Why we use dll in c#?

0 Answers  


Categories