1. Access rights for classes
|
The same class |
Same package |
Sub-classes under different packages |
Non-subclasses under different packages |
| Private |
√ |
|
|
|
| Default |
√ |
√ |
|
|
| Protected |
√ |
√ |
√ |
|
| Public |
√ |
√ |
√ |
√ |
2.4 Modifier final static This super
1.final
The modifier base type value cannot be changed;
The modified reference type reference cannot be changed, and the object of the invocation can be changed;
The modification method prevents inheritance modification;
The adornment class blocks inheritance.
2.static
Modifying properties and methods allows a class or method to follow a class without having to rely on an object.
3.this
1. In the class method, represents a reference to the method caller object.
2. In the first sentence of the constructor, the constructor that corresponds to the argument is called.
4.super
The child class maintains a reference to the parent class.
3. Reload vs Rewrite
Overloading: Is the same class, the method name + parameter list is different (parameter type and order);
Rewriting: The abortion relationship between the parent class and the subclass;
Subclasses inherit the parent class, which can be overridden, but the method name, parameter list, and return value need to be the same;
Child, the child class modifier cannot be less than the parent class. (The parent class would have public a method, but the subclass becomes private and destroys the consistency)
Java Classes and objects