Java-thinking in Java chapter 6th access Rights control

Source: Internet
Author: User

The basic object-oriented question: how to distinguish between things that change and things that remain unchanged.
Refactoring is rewriting the code to make it more readable, easier to understand, and therefore more maintainable.
Access rights: Public, protected, package access, private.
Local use, unnamed package, which is the default package.
Each file is the compilation unit, suffix. Java, after compilation, suffix. class.
Class Library packages, public all permissions, not named in-package permissions.
The naming conventions for Java packages all use lowercase letters, and so are the words that contain the middle.
The purpose of the package and import is to namespace and prevent name collisions.
The package name is the reverse-order Internet domain name of the creator, or it is named to try to avoid duplication.
The package statement must be the first line of non-commented program code in the file.
Static import classes can use methods directly.
Debugging is enabled during development and is prohibited in the release of the product, and is implemented by modifying the imported package.
JVN found the compiled (. Class) file through Classpath.

Ways to gain access outside of the class:
(1) Public, any can access.
(2) Unrestricted access to the word, the package can be accessed.
(3) Inheritance can access public and protected, within the package can access unlimited words, not outside the package.
(4) Get, set method access private.

The same directory does not give the package name, that is, in the default package, without qualifying words, giving the current class access rights.

Class access rights: Package access and public, additional restrictions:
(1) Each compilation unit (file) can have only one public class.
(2) The name of the public class must match exactly the file name containing the compilation unit, including case.
(3) There can be no public class, so the name is arbitrary.

constructor is set to private, you need to create a static method.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Java-thinking in Java chapter 6th access Rights control

Related Article

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.