1, access control modifier related
Visibility that is decorated by the public: The current class, the same package, subclasses, and other packages are visible.
Visibility modified by protected: current class, same package, subclass
Visibility modified by private: current class
No modifier modifier (Default): Current class, in same package
2, transient modifier
When a variable that is decorated with this modifier is serialized, the JVM virtual opportunity ignores the variable and is not serialized.
3, volatile modifier
Volatile decorated member variables force the value of the member variable to be re-read from shared memory each time it is accessed by the thread. Also, when a member variable changes, the thread is forced to write the change value back to the shared memory. So at any given moment, two different threads always see the same value for a member variable.
public class Myrunnable implements Runnable
{
private volatile Boolean active;
public void Run ()
{
active = true;
while (active)//First row
{
//code
}
} public
void Stop ()
{
active = false;//second line
}
}
In the example above, it is common for a thread to invoke the Run () method (a thread opened in Runnable) and a Stop () method on another thread. If the active value of the buffer in the first row is used, the loop does not stop if the active value of the second row is false.
But in the above code we use the volatile modifier active, so the loop stops.
4, Final modifier
(1) Final modifier variable
A final-decorated variable whose value can only be initialized once, that is, the value of the variable cannot be changed; The final-decorated object whose reference cannot be changed, but the value within the object can be changed.
(2) Final modification method
The final modified method can be inherited by the quilt class, but cannot be modified by quilts.
(3) Final modified class
The final decorated class cannot be inherited
5. Heavy Duty (overload)
Overloads (overloading) are in a class with the same method name and different parameters. The return type can be the same or different.
Each overloaded method (or constructor) must have a unique list of parameter types.
Overload rule:
(1) The overloaded method must change the parameter list (parameter number or type or order is not the same);
(2) The method of being overloaded can change the return type;
(3) The overloaded method can change the access modifier;
(4) An overloaded method may declare a new or broader check anomaly;
(5) The method can be overloaded in the same class or in a subclass.
(6) The return value type cannot be used as a distinguishing criterion for overloaded functions.
6, the existence of polymorphic three conditions
(1) Inheritance
(2) rewrite
(3) The parent class reference points to the child class object
Points to note:
The object that uses the reference of the parent class type to point to the child class;
Second, the reference can only invoke methods and variables defined in the parent class;
If a method in the parent class is overridden in a subclass, the method in the subclass will be invoked when the method is called, (Dynamic connection, dynamic invocation);
Variables cannot be overridden (overwritten), the concept of overriding is only for methods, and if you "override" the variables in the parent class in a subclass, the error occurs at compile time.
7, the abstract category summary stipulation
(1) Abstract class can not be instantiated, if instantiated, it will error, the compilation can not pass. Only non-abstract subclasses of abstract classes can create objects.
(2) An abstract class does not necessarily contain an abstract method, but a class with an abstract method must be an abstract class.
(3) Abstract methods in the abstract class are only declarations, do not contain the method body, is not given the concrete implementation of the method is the specific function of the method.
(4) Construction Methods, class methods (methods that are decorated with static) cannot be declared as abstract methods.
(5) Subclasses of an abstract class must give a concrete implementation of an abstract method in an abstract class, unless the subclass is also an abstract class.
8, Interface interface
(1) The interface cannot be instantiated, but it can be implemented. A class that implements an interface must implement all the methods described within the interface, otherwise it must be declared as an abstract class.
(2) An interface can inherit another interface
(3) The interface allows multiple inheritance, such as: public interface A extends B,c,d