Final, static, abstract differences and connections in Java

Source: Internet
Author: User

1. Static modifier static acts on code block: called Static code block (can initialize static field, cannot initialize non-static field); Static action on the Methods:static method only accesses the static method, The non-static method can access static fields only and cannot access non-static field non-static methods to access static fields and static methodsstatic  Method of two access methods Oject.method and Class.method, non-static method only Object.Method a way of access static  This and superstatic cannot be used as local variables (local variables include: function-level local variables and block-level local variables)  2, final modifier cannot be inherited (cannot have abstract final Class) (the method in the final class is automatically final, but does not include attributes) The final method can be inherited but cannot be override cannot have the abstract final Methodfinal property cannot be re-assigned (can be inherited, But not modifiable) can be initialized or uninitialized, and initialized in a statement block or initialized in a constructor (the latest to initialize in a constructor, Can only be initialized once) the final property can only be artificially assigned once and the final property of the parent class cannot be modified final can be decorated with local variables to represent local constants (method-level local variables (parameters and local variables, method body-level local variables) or block-level local variables)  3, Abstract modifier: An abstract class cannot instantiate an object an abstract class may not contain an abstract method, but as long as there is an abstract method the class must have no method body for the abstract class abstract method, A subclass of the Overrideabstract class is required to either implement all of its parent's abstract methods, or an abstract class abstract cannot modify a property abstract cannot modify a local variable (a method-level local variable (a parameter-level local variable). Method body-level local variable) or block-level local variable)  4, final, static, abstract relationship: final, abstract cannot coexist (no matter in class, method, attribute, local variable can not coexist) static, AbstracT cannot coexist (no matter in classes, methods, properties, local variables) can appear final static field (the class member property cannot be modified) can appear final static method (the class member method cannot be override)

Final, static, abstract differences and connections in Java

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.