Java vs. C# access modifiers looked at by a C# programmer
I had bookmarked long time ago a great C# vs. Java comparison Dave Obasanjo made:
A COMPARISON OF MICROSOFT'S C# PROGRAMMING LANGUAGE TO SUN MICROSYSTEMS' JAVA PROGRAMMING LANGUAGE
I noticed tonight that the member's access modifiers could use some tuning and show:
C# access modifier |
| Java access modifier |
private |
| private |
public |
| public |
internal |
| Default (package-private) |
protected |
| N/A |
internal protected |
| protected |
In Java, a protected member can only be accessed through classes on the same package and through subclasses whether they are on the same package or not.
The
protected
modifier specifies that the member can only be accessed within its own package (as with package-private or default) and, in addition, by a subclass of its class in another package. Package + Kids access.
The default access modifier in Java happens when a class member has no modifier (the default is also known as package-private). This means the member is only accessible by a class defined within the package.
Labels: Back to Basics, C#, Java