Java - Beginner - final keyword



In the above example, zi can modify Fu's show() function




=================================================

final can modify classes, methods, variables

=================================================

A. Modifiers

The bottom-level class is generally modified with final, "sterilized" and cannot have subclasses.


========================================================

B. Modification methods

This method cannot be overridden, or overridden


===========================================================

B. Modified variables

The variable cannot be recopied because the variable is actually a constant

There are two types of constants:

         A literal constant: 10, true, "hello"

         B custom constant: final int x = 10;


===========================================================

final decorates local variables:


1) Local variables are primitive data types


1) Local variables are reference types


 


===========================================================

The timing of initialization of final modified variables:

        ---Final modified variables can only be assigned once

        --- Occurs before the completion of the construction method (non-static constants, statics are already initialized when the class is loaded)












Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326840878&siteId=291194637