Thinking in Java note hiding implementation

Source: Internet
Author: User

Chapter 5 hide specific implementations
1. A compilation unit must have a suffix. Java, and a public class in the compilation unit. The class name must be the same as the folder name. A Java file can have only one public class.

2. The package name actually represents its directory structure.

3. If two packages are referenced in a file and they have a class with the same name, you need to use them all. You must specify the class in which the package is used ..

4. Access Permissions
1) package access permission (default access permission)
All other classes in the package have access permissions to that member, but this member is private for all classes outside the package.
2) public (interface access permission)
Anyone can access it anywhere.
3) Private
Except for the class containing this member, no other class can access this member.
4) protected (inherits the access permission)
The access permission is only granted to the derived class rather than all classes.

5. Default package
Java automatically considers a file that is in the same directory and does not set any package name for itself as the default package of the directory.

6. The classes cannot be private or protected. It can only be the package access permission or public. (Except for internal classes) 

 

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.