Keywords in Java

Source: Internet
Author: User

1. Final keyword

The final keyword in Java corresponds to the const keyword in c/C + +.

In Java, the final keyword can be used to describe a class, method, member variable:

. The final class cannot be inherited, there are no subclasses, and the methods in the final class are final by default.
. The final method cannot be overridden by a method of a class, but can be inherited.
. The final member variable represents a constant, which can only be assigned once, and the value will no longer change after the value is assigned.
. Final cannot be used to modify a construction method.
Note: The private member method of the parent class is not overridden by the class method, so the private type method defaults to the final type.

2. Static keyword

the static keyword in Java is similar to the static keyword in c/a + +.

In Java, the final keyword can be used to describe methods, member variables:

member variables and member methods that are modified by static are independent of any object of the class. That is, it does not depend on class-specific instances and is shared by all instances of the class.

The access syntax is:
Class name. static method Name (parameter list ...)
Class name. Static variable name

Keywords 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.