final keyword (Java)

final keyword meanings:

  Surface meaning: can not change the final.

  Like const keyword in C language, it refers to the amount can not be changed.

  But there is a difference of static variables, static variables refers to only one storage space, the value can change.

The final effect:

  1. Modified class: the final modified class can not be inherited;

  2. modification methods: final modified method can not be rewritten;

  3. modified variables: the final modified variable must be initialized, and can not be re-assigned after the initial value;

Why modified final variables?

  In fact, if a data is fixed, then use this data directly in the program on it,

  But this reading is poor, so they give a name to the data.

  And the value of this variable name can not be changed, so plus final fixed.

 

Guess you like

Origin www.cnblogs.com/benon94/p/10950554.html