Use of the Static keywordstatic means "' static," which can be used to modify properties and methods in Java. The application of the static keyword should be noted in the following scenarios: 1.static acts on a field, and a static field has
Java keyword static, final usage summaryStatic1. Static variablesThere are two ways to classify a class member variable statically: A variable that is statically modified, called a static variable or a class variable, and another variable that is
Java Static and final keywords
Static keyword: You can modify the property, you can also decorate the method, and you can use it to decorate the class.
Static Modifier property: Regardless of how many objects a class generates, all of these
StaticWhen declaring properties, methods in Java, you can use the keyword static to decorate.1.static variablesThere are two ways to classify a class member variable statically: A variable that is statically modified, called a static variable or a
Final
Final Variable (Before the keyword final is added to the defined variable, the variable is not changed once it is initialized.)
The specific meaning of an immutable term is:
Basic type whose value cannot be
Java modifiers fall into two main categories:
Access modifiers
Non-access modifiers
Non-access modifier java static
Static is a modifier, a static-decorated member variable and a member method that does not depend on a
First, final1.final variables:When you define a variable in a class and precede it with the final keyword, it means that once the variable is initialized it is immutable, and the immutable meaning is immutable for the base type, and the reference to
1. if a property field is modified in static mode, this property field becomes a resource of the class, and the public field is modified to a common one. You can use test outside the class. a. if it is modified to private, it can only be used within
static keyword: can be used to modify properties, can also be used for cosmetic methods, and can also be used to decorate classes. static modifier properties: Regardless of how many objects a class generates, all of these objects work together
Summary of private, static, and final identifiers
Reprinted from: http://zhidao.baidu.com/question/163628551.html
1. static indicates static. It belongs to the class. It can be called directly in its own class, or in other classes by class
For a final type of member variable, there are generally two ways of assigning an initial value1. Assign an initial value when declaring a member variable of the final type2. The initial value is not assigned when declaring a member variable of the
Learning the static and final Keywords of Java, javastaticfinal
Static: (static modifier) the content of static modifier in Object-Oriented objects belongs to classes rather than objects. Therefore, static modifier member variables are generally
Java Improvement (vii)-----keyword staticstaticThere is no concept of global variables in Java, but we can use static to implement a "pseudo-global" concept, where static in Java means "global" or "static," which is used to modify member variables
in the last few posts we know that when we write a class, we are actually describing the properties and behavior of the class object, and there is no real object, only the new keyword will produce the object, then the system will allocate memory
Static can modify variables, methods, or classes (ordinary classes cannot be modified with static and can only be used to decorate inner classes)Static variables are also called class variables (and the concept of global variables in C + + is the
I. Final
1. Final variable:
When you define a variable in a class and add the final keyword before it, this variable cannot be changed once initialized, the unchangeable meaning here is that its value is immutable for the basic type, and its
Java Notes 17. static and final usage in java,. javastaticIn the last few blog posts, we know that when we write a class, we are actually describing the attributes and behaviors of the Class Object, without generating a substantive object, the
// Jakarta commons LoggingPrivate Static final log = logfactory. getlog (myclass. Class );The above Code also shows another good practice, which is to pass The Class Object To the getlog () method, instead of a string.Why the java. util. Logging.
Static keywords:
It can be used to modify attributes in a class, methods in the class, and a specific class.
1. Used to modify attributes:
It indicates that this attribute belongs to the entire class. No matter how many object instances there are,
The difference between static and non-static is only revealed if the value is initialized during runtime. Because the values during compilation are considered by the compiler to be phaseThe same. Packagethinking; Public classFinalData {//Can be
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.