Random entry: Automatic type conversion in an expression
The char,short,byte is promoted to an int type and the result is int, but its original variable type does not change.
So, byte B = 10; b = b*b; Errors will be encountered at compile time. But written in B *=b; There's no problem.
—————————————— Gorgeous split-line ————————————————————————
Static and final
First, static
1. In front of the variable
Variables are static variables that can be called by the class name
2. In front of the method
Method is a static method that can be called by the class name
stored in a static area and can be accessed directly by all objects
Note: Only static methods or properties can be called in a static method
3. In front of the statement block
Static statement blocks are run once when the class is loaded
function to perform some initialization operations at class load time
PS: Static statement block is active load initialization, constructor is passive load initialization
4. In front of class
Static can only be preceded by an inner class
Second, final
1. Before the variable
Before the basic data type, it is a constant, can only be assigned once, the data can not be changed;
The object that the reference points to cannot be changed before the object reference, but the value of the object member can be changed;
2. Methods
Method cannot be overridden by a quilt class
3. Class
Cannot be inherited
—————————————— Gorgeous split-line ————————————————————————
Interface
1. Access control
Default: Available in Package
Public: Outside the package is also available and must be saved in a file of the same name
2. Methods
Method declarations contain only return types and signatures (method names and formal parameter lists), methods that implement an interface must be declared public
(All members in an interface are implicitly declared public)
If a class contains an interface, but does not fully implement the method of the interface definition, then the class must be declared abstract.
3. Variables
Implicitly declared as public, final, static, and must be initialized, which is actually a constant
4. References
A reference variable of an interface type can reference any object that implements its interface, and the method of that version of the object implementation will be executed when the object method is called through an interface reference. (The interface reference variable is only able to recognize the method that its interface declares)
Java Learning Diary-5 keywords static and final and interface