Java Learning (c)---modifiers

Source: Internet
Author: User
Tags modifier modifiers volatile

Access modifiers:

Default, public, private, protected

Non-access modifiers

Static

Static methods, static variables

Final

Final variable:

     The final variable can be displayed initialized and can be initialized only once. A reference to an object that is declared final cannot point to a different object. But the data in the final object can be changed. This means that the final object reference cannot be changed, but the value inside can be changed.

The final modifier is typically used with the static modifier to create a class constant.

Final method:

The final method in a class can inherit from a subclass, but cannot be modified by a quilt class

The primary purpose of declaring the final method is to prevent the method from being modified

Final class

Final class cannot be inherited

Abstrac modifier

Abstract class:

Abstract classes cannot be instantiated, and the only purpose of declaring an abstract class is to augment the class in the future.

A class cannot be both abstract and final decorated

Abstract method:

An abstract method is a method that does not have any implementation, and the specific implementation of the method is provided by the subclass.

Abstract methods cannot be declared as final and abstract

Any subclass that inherits an abstract class must implement all the abstract methods of the parent class, unless the subclass is also an abstract class

If a class contains abstract methods, then the class must be an abstract class, but abstract classes do not necessarily contain abstract methods.

Synchronized

The method of synchronized keyword declaration can only be accessed by one thread at a time. The synchronized modifier can be applied to four access modifiers.

Transient
When a serialized object contains an instance variable that is transient decorated, the Java Virtual Machine (JVM) skips that particular variable.

Volatile:

A decorated member variable forces the value of the member variable to be reread from shared memory each time it is accessed by the thread. Also, when a member variable changes, the thread is forced to write the value of the change back to the shared memory. So at any moment, two different threads always see the same value for a member variable.

A volatile object reference may be null.

Java Learning (c)---modifiers

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.