The difference between Java modifier abstract,static,final

Source: Internet
Author: User

Note: classes with abstract methods must be abstract classes. But abstract classes are not necessarily abstract methods, but they can all be concrete methods.
The abstract modifier must be placed before the class name when decorating the class.

The abstract modification method is to require its subclasses to overwrite (implement) this method. Calls can be called in a polymorphic way after a subclass overrides (implements) the method, which means that the abstract method must be implemented in its subclasses, unless the subclass itself is an abstract class.

Note: The parent class is an abstract class, in which there is an abstract method, then the subclass inherits the parent class and implements (overwrites) all the abstract methods in the parent class, and the subclass has the ability to create an instance of the object, or the subclass must be an abstract class. An abstract class can have a constructor method, which is the constructor of the parent class (abstract class) that the subclass needs to call when constructing the subclass object.

Final and Abstract,private and abstract,static and abstract, these are modifiers that cannot be put together, because the method of the abstract adornment must be implemented (overwritten) in its subclasses in order to be called in a polymorphic manner. The above modifiers are not covered by this method at the time of the modification method, final is not overwritten, private is not able to inherit to subclass, so it cannot be overwritten, static can be overwritten, but the method of the compile-time type is called when called, because the method of the parent class is called. The method of the parent class is an abstract method and cannot be called, so the modifiers on it cannot be put together.

The abstract method represents a standard, defines a standard, defines a function, implements functionality in subclasses (subclasses inherit the parent class and need to give an implementation of an abstract method inherited from the parent class).
The method can be defined as abstract when it is unexpected how it is implemented, or if it is intended to be implemented by subclasses to define a standard. (abstract)

Template method Mode
Use abstract to set standards and implementation standards separate, the standard is the template, the implementation is the template standard to achieve, that is, inherit the template, to implement the corresponding function in the template method. A method that does not allow modification in a template can be decorated with fianl, which does not allow the abstract method to be used to ensure security, encapsulation, and protected (protection) of the parts of the template that are not exposed.

The difference between Java modifier abstract,static,final

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.