Below is a table mapping C# access modifiers to Java's. C++ fans who were disappointed when Sun changed the semantics of the
protected
keyword in Java 2 will be happy to note that the C#
protected
keyword has the same semantics as the C++ version. This means that a
protected
member can only be accessed by member methods in that class or member methods in derived classes but is inaccessible to any other classes. The
internal
modifier means that the member can be accessed from other classes in the same
assembly as the class. The
internal protected
modifier means that a member can be accessed from classes that are in the same assembly or from derived classes.
C# access modifier | Java access modifier |
private | private |
public | public |
internal | protected |
protected | N/A |
internal protected | N/A |
NOTE: The default accessibility of a C# field or method when no access modifier is specified is
private
while in Java it is
protected
(except that derived classes from outside the package cannot inherit the field).
No comments:
Post a Comment