Java Records -17-static and final keywords

Source: Internet
Author: User

Java Static and final keywords

  1. Static keyword: You can modify the property, you can also decorate the method, and you can use it to decorate the class.

  2. Static Modifier property: Regardless of how many objects a class generates, all of these objects work together to use a unique static member variable, and one object modifies that static member variable, and the value of that static member variable for the other object changes as well. If a member variable is static, then we can use it in the same way as the class name. Member variable name (recommended in this way).

  3. Static Modification Method: The method of static modification is called a stationary method. For static methods, you can use the class name. Method name to access it.

  4. Instance method: An instance method in a subclass and an instance method in the parent class, with the same signature, the subclass method will override the parent class's method.

    Class method: If a subclass defines a static method that has the same signature as the parent class, the method hides the static method of the parent class in the subclass.

    Subclasses do not override static methods of the parent class, but are hidden.

    Official information:

    Https://docs.oracle.com/javase/tutorial/java/IandI/override.html

  5. The important differences between hiding a static method and overriding an instance method are as follows:

    1). Overriding an instance method call is a method in a subclass;

    2). The call to hide a static method depends on whether the call comes from the parent class or the child class.

  6. Static methods can only inherit and cannot be overridden (override).

Java Records -17-static and final keywords

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.