Can the abstract method be both static, native, and synchronized?

Source: Internet
Author: User

1. abstract and static

(What)

Abstract: It is used to declare abstract methods. abstract methods do not have a method body and cannot be called directly. They must be used after the subclass overriding.

Static: Used to declare static methods. Static methods can be called by classes and objects.

(How)

Static and abstract cannot be used at the same time

(Why)

The static declaration method indicates that this method can be called directly when no class instance is generated, but the abstract method cannot be called, which is in conflict.

2. abstract and native

(What)

Native: Used to declare a local method. The implementation of this method is implemented by a non-Java language, such as C. It is generally used for JAVA interaction with external environments or operating system interaction.

(How)

Native can be used with all other Java identifiers, except abstract.

(Why)

Because native implies that these methods have implementations, but these implementations

It is not Java, but abstract clearly specifies that these methods have no implementation bodies.

3. abstract and synchronized

(What)

Synchronized: Used to prevent multiple threads from calling this method of an object at the same time. It is used with static to prevent multiple threads from simultaneously calling this method of a class.

(How)

Abstract and synchronized cannot be used simultaneously

(Why)

We can also see from the synchronized function that the premise of using synchronized is that this method can be called directly, obviously used with abstract

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.