Java4android Basic Learning Package and access rights

Source: Internet
Author: User

1. Package

1) Package: Packages The class, while restricting access rights

2) package creation, package + Pack name (package name usually by domain name + specific name) such as:

 Package Com.baidu;  Public class Person {}

This code is implemented to package person into Com/baidu, where registration is the domain name + specific name; Here the full name of this class is Com.baidu.person.

3) The import of the package, using the Import + package name. The class name is imported, such as:

Import Pack.person;  Public class Test {    publicstaticvoid  Main (String args []) {    }}

In this way, the member variables and member functions in the person class can be used in the test class.

2. Access rights

1) There are four types of access rights, as follows:

 Public // in common, any class in any package can be accessed default // Default (default is not written), can only be accessed in the same package protected // protected, the same package can be accessed, while subclasses can be accessed (including subclasses in different packages) Private // private, only this class can access

2) When a class is defined as public, the name of the class must be the same as the file name.

Java4android Basic Learning Package and access rights

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.