[Java] Final Keyword of Java Foundation

 Final means final, classes, methods and variables can be modified in Java.

Final modification class:

  When the class is final modified, the class represents the final class, no descendants, can not be inherited

//最终类
public final class Person{
}

When this class is inherited, the following error will be generated:

final modification method

The method modified by final is the final method and cannot be overridden

//最终方法
public final void eat(){
    System.out.println("吃饭");
}

When this method is modified, the following error will be displayed:

final modified variable

Role :

        1) Variables modified by final become constants and cannot be modified,

         2) When naming final modified variables in java, all letters are capitalized, and words are separated by "_"

Modified the difference between basic types and reference types:

        1) Basic types store values, reference types store address values

        2) The basic type of final modification is that the value cannot be changed

        3) The address value cannot be changed when the reference type is final modified

Guess you like

Origin blog.csdn.net/weixin_43267344/article/details/107866057