RSS Feed Subscribe to RSS Feed

 

Java vs .Net Accessor Modifiers

I’ve been looking at some .Net code recently, and I wanted to do some comparisons on Java access modifiers vs .Net to help me better understand the code.

In Java, the modifiers are (in order of least to most visible):

private, default (or package level), protected and public.

In .Net, I believe they are:

private, protected, internal, protected internal, public

My understanding of the comparisons of the Java vs .Net modifiers are (again in order of least to most visible):

Java .Net Notes
private private only accessible from within its own class N/A
default N/A package level access
N/A protected accessible from subclasses
N/A internal internal means accessible from the same assembly.
In Java this would be accessible from the same jar
but Java doesn't support such a mechanism.
protected protected internal In Java, means accessible from any subclass,
or any class in the same package
In .Net it means accessible in the same assembly,
or from within a derived class in another assembly
public public Accessible from any class

						

Tags: , , ,

Leave a Reply