Package. Import. Class in Java and comparison with C ++ (1)

Source: Internet
Author: User

The packages in the Package java are similar to the namespace in C ++. They are mainly used to prevent name conflicts. The class is included in the package. The package statement should be placed at the beginning. The statement format is generally: package name; for example: [java] view plaincopyprint? Package java. basic; package java. basic; Import in java, similar to include in C ++, the format is as follows: [java] view plaincopyprint? Import java. util. Data; import java. util. Data; classes in Class java are basically the same as those in C ++, but the three access permissions are different. In C ++, the three permissions are as follows: attribute access permission public all protected itself. the sub-class private is only in java. The three permissions are as follows: the attribute access permission is public, and all protected itself. subclass (both inside and outside the package ). all classes in the current package are private. The main difference is protected. in java, all classes in the current package can access members of the protected attribute. In addition, C ++ uses the public attribute by default, while in java, the accessibility of the default attribute is as follows: itself, all classes in the current package. This: this is the same as C ++. Super: This is used in java to access the parent class.

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.