Access permissions for Java and C #

Source: Internet
Author: User

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 #

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.