Protected Accessibility Level in Java vs C#
This topic should be discussed in two different sections; one for scenarios where no static members are involved and next for scenarios in which static members are involved. This post is for the scenarios where all members are non-static.
In Java protected is the next least restrictive after public. Protected class members can be accessed by:
1. All classes/methods that are in the same package.
2. Sub-classes of the class of the protected members.
In C#, as explained in Default Class Accessibility in C#, protected class members are accessible by sub-classes of the class of the protected members.
To convert Java code of a protected member into C# code, the protected member must be declared as protected internal.
Comparing protected members of Java and C# for scenarios involving static members will be discussed in a next post.
This topic should be discussed in two different sections; one for scenarios where no static members are involved and next for scenarios in which static members are involved. This post is for the scenarios where all members are non-static.
In Java protected is the next least restrictive after public. Protected class members can be accessed by:
1. All classes/methods that are in the same package.
2. Sub-classes of the class of the protected members.
In C#, as explained in Default Class Accessibility in C#, protected class members are accessible by sub-classes of the class of the protected members.
To convert Java code of a protected member into C# code, the protected member must be declared as protected internal.
Comparing protected members of Java and C# for scenarios involving static members will be discussed in a next post.
Copyright ©2017, Software Developer, All rights reserved.
See Contents
No comments:
Post a Comment