[Part 4 - Comparing Java & C#] Class Access Modifier

Using class access modifiers is to control access level for other classes  Controlling access is used almost for methods or nested classes. Also questions about the access modifiers are usually at exams and interviews.

  C#

The below table is taken from the book C# Language Specs:
In same namespace, the default for non-nested class must be internal or public.


Accessibility
Meaning
public
Access not limited
protected
Access limited to this class or classes derived from this class
internal
Access limited to this program
protected internal
Access limited to this program or classes derived from this class
private
Access limited to this class

Defaults:
The default for non-nested types is internal. The default for nested types is private. In both cases the default (for classes) is unsealed. The general rule for all members is that if you don't specify an access modifier, it's as private as it can be. The single exception for this is properties which can make one part (i.e. the getter or the setter) more private than the overall property by specifying an access modifier, e.g. (Jon Skeet)

Java

The below table belongs to Oracle,  http://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html
Access Levels
Modifier Class Package Subclass World
public Y Y Y Y
protected Y Y Y N
no modifier Y Y N N
private Y N N N
The default is no modifier.
Share on Google Plus

About Chien

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.

0 comments:

Post a Comment