[Java entry] -- Java modifier Summary

Source: Internet
Author: User

The Java language defines the six common modifiers public, protected, private, abstract, static, and final.
Five frequently-used modifiers are also defined. The following describes the 11 Java modifiers:

1. public

Objects used: classes, interfaces, and members

Introduction: No matter where the package is defined, this class (interface, member) is accessible.

2. private

Intended audience: Members

Introduction: A member can only be accessed in the class that defines it.

3. static

Object used: Class, method, field, initialization Function

Introduction: an internal class named static is a top-level class, which is irrelevant to the members of the class. Static Method
Is a class method,

Is to be directed to the class rather than the instance of the class. A static field is a class field.
Number of instances.

Only one instance is pointed to the class rather than the instance of the class. The initialization function is executed when the class is loaded.
Instead of creating

Executed when the instance is running.

4. final

Objects used: classes, methods, fields, and variables

Description: A class defined as final cannot contain child classes, cannot be overwritten (cannot be used for dynamic queries), and field values.
Not Allowed

Modify.

5. abstract

Objects used: classes, interfaces, and methods

Description: classes include methods that are not implemented and cannot be instantiated. If it is an abstract method, the method body
Null.

The implementation of the method is defined in the subclass, and the class that contains an abstract method must be an abstract class.

6. protected

Intended audience: Members

Introduction: A member can only be accessed in the defined package. If it is accessed in another package, the class that implements this method
It must be

Subclass of the member's class.

7. native

Intended audience: Members

Description: it is related to the operating platform. Its method is not defined when it is defined. The implementation of the method is implemented by an external library.

8. strictfp

Objects used: classes and Methods

Introduction: all methods in the strictfp modifier class hide the strictfp modifier and all floating points of method execution.
Computing compliance

IEEE 754 standard. All values, including intermediate results, must be of the float or double type, but cannot be used.
Floating by local platforms

The extra precision or representation range provided by the point format or hardware.

9. synchronized

Usage object: Method

Introduction: For a static method, jvm locks the class in which it belongs before execution. For a non-static class
Method, execution

Before locking a specific object instance.

10. volatile

Use object: Field

Introduction: Because the asynchronous thread can access fields, some optimization operations cannot be applied to fields.
Volatile sometimes

Synchronized can be replaced.

11. transient

Use object: Field

Description: fields are not part of the object's persistent State and should not be concatenated with objects.

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.