The use of modifiers used in Java programming

Source: Internet
Author: User
Tags abstract definition final modifiers static class volatile

The Java language defines the 6 common modifiers of public, protected, private, abstract, static, and final, as well as 5 less commonly used modifiers, and below is an introduction to the 11 Java modifiers:

1.public

Working with objects: classes, interfaces, members

Description: The class (interface, member) is accessible regardless of the package definition in which it is located

2.private

Working with objects: members

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

3.static

Working with objects: classes, methods, fields, initialization functions

Description: An inner class that is famous for its static is a top-level class that is irrelevant to the members of the containing class. A static method is a class method that is directed to the owning class, not to an instance of the class. A static field is a class field, and no matter how many instances the class in which the field is created, there is only one instance of the field that is pointed to the class that belongs to, not the class. The initialization function executes when the class is loaded, not when the instance is created.

4.final

Working with objects: classes, methods, fields, variables

Description: A class that is defined as final does not allow subclasses, cannot be overwritten (not applied to dynamic queries), and field values are not allowed to be modified.

5.abstract

Working with objects: classes, interfaces, methods

Description: The class includes methods that are not implemented and cannot be instantiated. In the case of an abstract method, the method body is empty, 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

Working with objects: members

Description: A member can only be accessed in a package that defines it, and if it is accessed in another package, the class that implements the method must be a subclass of the class to which the member belongs.

7.native

Working with objects: members

Introduction: In relation to the operating platform, the definition does not define its method, and the implementation of the method is implemented by an external library.

8.strictfp

Working with objects: classes, methods

Description: All methods in the STRICTFP decorated class hide the strictfp modifier, all floating-point computations performed by the method comply with the IEEE 754 standard, and all values including intermediate results must be represented as float or double types. You cannot take advantage of the extra precision or presentation scope provided by the local platform floating-point format or hardware.

9.synchronized

Working with objects: methods

Description: For a static method, the JVM locks its class before execution, and locks a particular object instance before execution for a Non-static class method.

10.volatile

Working with objects: Fields

Introduction: Because Asynchronous threads can access fields, some optimizations do not work on fields. Volatile can sometimes replace synchronized.

11.transient

Working with objects: Fields

Description: A field is not part of an object's persistent state and should not be strung together with the object.

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.