C# FAQ: What are the differences between CSharp and Java access modifiers
Microsoft .NET Framework, ASP.NET, Visual C# (CSharp, C Sharp, C-Sharp) Developer Training, Visual Studio
| CSharp-Online.NET:FAQs |
| edit |
What are the differences between C# and Java access modifiers?
The default accessibility of a Java member if no access modifier is specified is protected except that subclasses in other packages cannot inherit the member. The default accessibility of a C# member if no access modifier is specified is private.
The following table shows how the C# access modifiers correspond to those of the Java language.
| Access Modifiers | |
| C# | Java |
private
| private
|
public
| public
|
internal
| protected
|
protected
| na |
internal protected
| na |
The C# protected keyword shares the same semantics as the C++ equivalent. Accordingly, a protected member is inaccessible except by member methods either in the same class or in subclasses.
The internal modifier specifies that the member can be accessed by classes in the same assembly.
The internal protected modifier specifies that a member can be accessed from either subclasses or by classes in the same assembly.