1. Static members
Static members are independent of the class's objects, and exist before the existence of the object. Static members have only one instance space, regardless of how many objects of a class are created. A static variable is shared by all objects of the same class. When you change the static variable of one of the objects, the values of the static variables of the remaining objects change accordingly, because they share the same amount in the same space.
Because static variables are independent of specific objects, static variables are defined and can be invoked in the following two ways:
Object name. Static variable Name
Class name. Static variable Name
2. Static methods
Static methods are commonly defined in the form of:
public static int out () {
Method body
}
Static methods use:
The name of the object. Static method Name
Class name. static method Name
3.final
Final class
Some classes are well-defined when writing a program. For consistency or security reasons, you do not want to be inherited by another class, you should decorate the class as the final class. The final class cannot be inherited.
Public final class test{
Class Body
}
In Java, many common classes are final types, such as String strings, math classes, math, and so on.
Final member
Final-Modified member variables are called constants
The final decorated member method is called the final method, and the resulting method cannot be overridden in the derived subclass of the current class. The final method defines the form:
Public final void out () {
Method body
}
[Java] Static, final