6.static, Final keywords

Source: Internet
Author: User

1. Static member variable 1.1 can be called either with the object name or directly with the class name to call person.i = 10; Person is a class name.   I is a member variable; a class name. member variable =; The function of a static variable: A variable shared by all instance variables of the same type. Tip: A static variable is initialized before any static methods of the class are executed.
1.2 He is not an object-level variable, it is a class-level variable, it belongs to a class.
2. Static function 2.1 function in front of the static keyword, can be called directly with the class name; 2.2 Because this is not available, soa static function cannot reference a non-static variable.
Tip: Static methods cannot invoke non-static variables/methods.      Because a static method is called by the name of the class, a static method cannot refer to any instance variable of the class. Static method calls have no objects. 3. Static code block he has no name.    is to execute itself when loading the class, assigning the initial value to the static member variable, using less.   A starter program suitable for putting static final variables. static{The code is .....   }
4.final1. A variable marked as final indicates that it will not be altered once it has been initialized. Constants in 2.java are defined as public static final double PI = 3.14 constant names should all be uppercase letters.   3.final is not only used on static variables, it can also be used to modify non-static variables. A final variable represents a method that cannot change the final value to represent a class that cannot override the final.


From for notes (Wiz)

6.static, 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.