Access modifiers
Private access rights: this class
Default access rights: Same package
Protected access rights: Same bun Category
Public access rights: all can
Packaging
Makes the member variables in a class private and becomes data-hidden.
Benefits of Encapsulation:
A member variable of a class can be read-only or write-only;
A class can have a holistic control over what is stored in its member variables.
The user of the class does not need to know how the class stores the data.
Static members
The static method cannot manipulate any properties and methods that are not static.
Cause: 1, static is the class level, regardless of the object.
2, static modification is the first family, the non-static at this time has not been loaded into memory, so can not access.
The tool method for writing tool classes is modified with static.
A non-static method is one that can manipulate any property and method of static.
Initialize block
{
}
Instance initialization block: Automatically executes when the object is generated, after the constructor of the parent class, before the class constructs the method
The usage is very small, because the code can be written to the first few lines of this class construction method.
Static initialization blocks
static{
Automatically executes when the class is loaded and executes only once.
Use is very high, usually put some of the pre-run preparation work here, let it in the loading period to complete the preparation.
Inner class
member Inner class
1, can have access modifiers
2. class file name: External class class name $ internal class class name. class
3, is a complete independent class
4, in any non-static method of this class can be new out, in a third-party class must use the external class object. The new method produces the inner class object.
Local inner class
1. Cannot have access modifiers
2. class file name: External class class name $ ordinal + inner class class name. class
3, is a complete independent class
4, in this method can produce objects, and then use.
Static Inner class
1, can have access modifiers
2. class file name: External class class name $ internal class class name. class
3, is a complete independent class
4, in any method of this class can be new out, in the third party class to new out, no need to produce an external class object, just use the external class name. The way is possible.
Anonymous inner class
Because there is no class name, it is used to tell the JVM its structure when the object is produced.
can only be used 1 times.
class file name: Outer class class name + ordinal. Class
The eighth chapter summarizes