Static abstract methods are not defined in abstract classes and interfaces in Java

Source: Internet
Author: User
1. There is no static abstract method in Java abstract class.

Abstract classes cannot be instantiated, that is, memory cannot be allocated, and static-decorated methods do not allocate memory until the class is instantiated, so the contradiction arises: the abstract class cannot be allocated memory, and the static method must be allocated memory. Therefore, abstract classes cannot have static abstract methods.

The purpose of defining an abstract method is to override this method, but cannot be overridden if it is defined as a static method.

2, the interface can not have a static abstract method

The methods in the interface can only be public abstract decorated, and cannot be added with static. Interfaces cannot be instantiated, that is, memory cannot be allocated, and static-decorated methods do not allocate memory until the class is instantiated, so the contradiction arises: the interface cannot be allocated memory, and the static method must be allocated memory. Therefore, there can be no static abstract method in the interface.

3. Abstract classes do not necessarily have abstract methods

Static statics are byte-coded.

An abstract class can have no abstract method, using abstract only to not be instantiated.

The above two points can be explained that the static method can be run as long as the bytecode exists, so there can be static methods in the abstract class.

4, static and abstract can not exist on the method of common

Because the static belongs to the bytecode, does not need the object to be able to run, but the abstract method does not have the method body, the operation does not have the meaning, therefore cannot coexist.

Static abstract methods are not defined in abstract classes and interfaces in Java

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.