Access permissions for Java and C #
There are four access rights in Java:
Scope _____ Current class ____ Same package___ descendant class ____ Other package
Public (class or member) √√√√
Protected (Member) √√√x
Default (class or member) √√XX
Private (Member) √xxx
"Note":
1. A Java file can contain multiple classes, but there must be a class public and the class name is the same as the file name, and the other classes are default permissions.
The 2.java class can contain inner classes, internal class names cannot be the same as outer layers, and internal classes have the same access and member permissions, inner classes can not have static members, static initialization blocks, static methods, etc.
3. Classes and interfaces have the same kind of access rights
-------------------------------------------------------------------------------
"Access rights in C #":
Scope _____ Current class ____ The same namespace___ descendant class ____ Other namespace
Public (class or member) √√√√
Internal (class or member, class default; The visitor must be under the same assembly) √√√√
Protected (Member) √√√x
protected internal (member, accessed must be under the same assembly) √√√x
Private (Member, member default) √xxx
"Note":
1. A C # file can contain only one class, but the class name does not need to be the same as the file name, and the C # class may contain inner classes.
The inner class in 2.c# is independent of the object of the outer class, whereas in Java, the inner class is related to the object of the outer class.
C # Inner classes have the following characteristics:
1. Internal classes and external classes cannot access instance members to each other.
2. The external class can access the internal and public static members of the inner class.
3. An inner class can access all static members of an external class.
4. The maximum access permission for an internal class is limited to namespace, even if both the inner and inner classes are declared public, but the methods in the other namespace still cannot access and instantiate the inner class.
Access permissions for Java and C #