Characteristics of the fine chemicals java static, final, static final of

Characteristics of the fine chemicals java static, final, static final of

Today, when I write java encountered a static variable, but some confusion between temporary static, final, static final difference between the three of them, so I'm going to look carefully to distinguish the differences between them.

final

final methods may be modified, class, local variables

1.final initialization properties can be modified at compile time, you can also run, it can not be changed after initialization.

2.final modified with specific properties related to the object, at runtime initialization of the final properties of different objects can have different values.

3.final modified attribute indicates is a constant (can not be changed after you create).

4.final modified method indicates that the method can not be overridden in a subclass, final modified class represents the class can not be inherited.

For primitive types, final value will be changed to a constant (can not be changed after creation); however, the object handle (also referred to as a reference or a pointer), final passes a handle becomes a constant (when declaration must be initialized to handle a particular object. and can no longer handle to another object, but the object itself can be modified. this limitation also applies to the array, the array also belong to the object, the array itself can be modified. method parameter the final handle, means that inside the method, we can not change what the actual argument handle points, that is to say in the internal methods can not handle another addition to the formal parameter assignment).

static

static can be modified: properties, methods, code segments, an internal class (static class or nested inside inner class)

(When the class is loaded) 1.static modified initialization properties at compile time, after initialization change.

2.static modification of the properties of all objects have only one value.

3.static modified attributes to emphasize only one of them.

4.static modified properties, methods, code snippets nothing to do with the specific object of this class, create an object can not be modified to call static properties, methods, etc.

5.static and "this, super" irreconcilable, has nothing to do with the specific static objects, and this, super just to do with the specific object.

6.static local variables can not be modified.

static final和final static:

static final and final static no difference, generally static EDITORIAL.

static final:

static modification of the properties they emphasize only one, final modified attribute indicates is a constant (can not be changed after you create). static final modified attribute value to represent once, it can not be modified, and may be accessed via the class name.

static final method can also be modified to indicate that the method can not be overridden, can be called without new object

Released five original articles · won praise 1 · views 258

Guess you like

Origin blog.csdn.net/zhanghongbin159/article/details/101098919