1, the interface modifier only: public
2. The modifiers of the class are divided into two types: accessible and non-access control characters.
The accessibility control characters are: public class modifiers
Non-access control characters are: abstract class modifier abstract; final class modifier final
1. Common class Modifiers public : There is only one accessible control character for classes in the Java language: public. The main class for each Java program must be a public class as a common tool for use by other classes and programs that should be defined as the publicly class.
2. Abstract class modifier abstract : Any class decorated with the abstract modifier is called an abstract class. An abstract class is a concept class that does not have a specific object for such a class. Such a class is the abstract class of the Java language.
3. Final class modifier final : When a class cannot have subclasses, the modifier final can be used to describe it as the final class. A class that is defined as final is usually a class that has fixed functions that are used to accomplish some standard function.
4. Class default Access control character: If a class does not have an access control character, it has the default access control character attribute. At this point, the class can only be accessed or referenced by classes in the same package. This access feature is also known as package accessibility.
3, the control modifier for the property is also divided into two categories: accessibility and non-access control characters.
There are 4 accessible control characters: Public access control character: Private access control character: private; protection access control character: Protected private protection access control character: private protected
There are 4 types of non-access control characters: Static field modifiers: statically; final field modifiers: final; volatile (shared) field modifiers: volatile; temporary domain modifiers: transient
1. Public access control character: a domain decorated with public is called a common domain. If the public domain belongs to a common class, it can be referenced by all other classes. Because the public modifier reduces the security of the operation and the encapsulation of the data, you should generally reduce the use of the public domain.
2. Private Access Controller private: A member variable (field) decorated with private can only be accessed by the class itself, not by any other class, including subclasses.
3, protect access control character protected: the member variable decorated with protected can be referenced by three kinds: ① the class itself, ② other classes in the same package as it does, and ③ subclasses of the class in the other package. The primary role of using modifiers protected is to allow its subclasses in other packages to access specific properties of the parent class.
4. Private protection access control character private protected: A member variable decorated with the modifier private protected can be accessed and referenced by the class itself or by the subclass two of the class.
5. Static field modifier static: A member variable decorated with static is only a variable of a class, not a specific object, and the value of a static member variable is a public storage unit stored in the memory area of the class, rather than a memory interval that is saved in an object. When an object of any class accesses it, it takes the same data, and the object of any class modifies it to operate on the same memory unit.
6, final domain modifier final: Final field modifier final is used to define symbolic constants. The domain of a class (member variable) is invariant if the modifier is final, and its value is unchanged throughout the execution of the program.
7. Volatile (shared) field modifiers volatile: volatile (shared) domain modifiers volatile are used to indicate that this member variable may be controlled and modified by several threads. This means that the member variable may be affected by other programs or changed its value in the process of running the program. Therefore, we should pay attention to the change of the value of this member variable in use. Typically, volatile is used to decorate fields that accept external input.
8, temporary domain modifier transient: temporary domain modifier transient used to define a transient variable. It is characterized by the use of modifiers transient limited temporary variables, the specified Java virtual machine to determine that the temporary variable is not a permanent state, to achieve the archiving function of different objects. Otherwise, all the variables in the class are part of the permanent state of the object, and the variables must be saved when the object is stored.
4. The control modifiers of the method are also divided into two categories: accessibility and non-access control characters.
There are 4 accessible control characters: Public access control character: Private access control character: private; protection access control character: Protected private protection access control character: private protected
There are 5 types of non-access control characters: Abstract method control characters: Abstracts; static method control characters: Static; Final method control character: final; local method controller: Native; Synchronization method control character: synchronized
1. Abstract method Control character Abstract: A method that is decorated with the modifier abstract is called an abstract method. An abstract method is a method with only a method header, no method body, and an operation implementation.
2. static method control character static: A method decorated with modifier static is called a static method. A static method is a class method that belongs to an entire class, and a method that is part of a specific class object without using a static modifier or a qualified method. Because the static method is part of the entire class, it cannot manipulate and process member variables belonging to an object, but only member variables that belong to the entire class, that is, the static method can handle only static fields.
3. Final method Control final: A method that uses the final modifier of the modifier is called the final method. The final method is a method that cannot be changed by functionality and internal statements, that is, the final method cannot be overloaded. In this way, the function and operation of the method are fixed, which prevents the subclass of the current class from defining the key methods of the parent class, and ensures the security and correctness of the program. All methods defined as private by the private modifier, and all methods contained in the final class (end Class), are considered the final method.
4. Local method Control native: A method decorated with modifiers native is called a local method. In order to improve the running speed of the program, it is necessary to use other high-level language to write the method body of the program, then the method can be defined as the local method with modifier native to modify;
5, synchronization method control character synchronized: This modifier is mainly used for multithreading coexistence of the coordination and synchronization in the program.