Monday, May 25, 2009

Java vs. C# access modifiers looked at by a C# programmer

I'm looking into the SCJP 6 as I don't have hands on experience on Java projects (only academic apps).
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: , ,

0 Comments:

Post a Comment

<< Home