Java Access Permissions

Source: Internet
Author: User

Java Access Permissions
1. public modifier, indicating that the Members are public and all other classes can be accessed;
2. The private modifier indicates that the member is private and can only be accessed by itself;
3. No modifier, indicating the package access permission (friendly), which can be accessed in the same package;
4. protected indicates the protected permission, which is embodied in inheritance. That is, the subclass can access the protected members of the parent class, and other classes in the same package can also access the protected member.
5. Class access restrictions. Only public and package access permissions are allowed.
A. a Java file can have only one public class
B. the name of the public class must be exactly the same as that of the Java file.
C. If there is no public class in the Java file, the file name can be arbitrary.
6. final keywords
A. final data members are always initialized and forced to assign values in the definition or constructor before use. Once assigned, their values for basic types remain unchanged, the object reference always points to the assigned object, but the object itself can be modified;
B. final parameters. for basic types, the parameter values cannot be changed. For object references, the objects referred to by the reference cannot be changed;
C. final methods to ensure that the methods are not modified and reloaded after inheritance; all private methods are implicitly final; dynamic binding (post-binding) is used in Java to achieve polymorphism, except the static and final methods, they are pre-bound;
D and final classes, indicating that the class cannot be inherited.

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.