Method
MethodIs a class function and process. They are local to the class and are not stored outside the class. Methods can be called only within a class or through an instance of the class. methods can access all public, protected, and private fields. Methods can be declared in private, protected, or public segments. To design a better class, consider which methods should be placed in the class.
Common method(Public method) andAttribute(Property) represents the interface between the user and the class. Through public methods, the user of a class can access the class to obtain the functions provided by the class. For example, if a class is used to play and record audio, the common methods may be open, play, record, save, rewind, and so on.
Private Method(Private method) is a class used to handle internal affairs. These methods cannot be called by class users. They are private for hiding them from the external world. To create a class, you usually need to process initialization tasks, the initialization process of some classes is very important and may require a lotCodeTo delete unnecessary items from the constructor, the class may needInitMethod, by calling in the constructorInitMethod to initialize the task. Class users cannot directly call this method. In fact, if you call this method when it is not appropriate, it may lead to worse cases. Therefore, this method is private, this not only protects the integrity of the class but also protects the user.
Protection methods(Protected method) is also a method. This method cannot be accessed by the outside world, but it can be accessed by the derived class of this class. Currently, there is no problem of deriving another class from one class, I will not discuss it for the moment.Inheritance.
The method can also be declaredClass Method(Class method ). A class method is more like a normal function and process than a class method. In particular, a class method cannot access fields or other methods of the class. So much for now.