Overriding is a manifestation of the polymorphism between the parent class and the child class, and Overloading is a manifestation of the polymorphism in a class. The Overloaded method can change the type of the returned value. That is to say, the type of the returned value of the overload can be the same or different. Overriding is a manifestation of the polymorphism between the parent class and the child class, and Overloading is a manifestation of the polymorphism in a class. The Overloaded method can change the type of the returned value. That is to say, the type of the returned value of the overload can be the same or different.
Overloading)
A. Method overloading is a means for classes to process different types of data in a unified manner. Multiple functions with the same name exist at the same time and have different parameter numbers/types. Overload Overloading is a manifestation of polymorphism in a class.
B. Java Method overloading means that multiple methods can be created in the class. they have the same name, but have different parameters and different definitions. When calling a method, the number and type of different parameters passed to them are used to determine which method to use. this is polymorphism.
C. during overload, the method name must be the same, but the parameter type and number are different. The return value type can be the same or different. Return types cannot be used as the criteria for distinguishing heavy-duty functions.
2. Overriding)
A. The polymorphism between the parent class and the child class, and the function of the parent class is redefined. If a subclass defines a method with the same name and parameter as its parent class, we say this method is overwritten ). In Java, subclasses can inherit the methods in the parent class without re-writing the same method. But sometimes the subclass does not want to inherit the parent class from the original method, but wants to make some modifications, which requires method rewriting. Method override is also called method override.
B. If the method in the subclass has the same method name, return type, and parameter table as a method in the parent class, the new method overwrites the original method. ** If you need the original method of the parent class, you can use the super keyword, which references the parent class of the current class **.
C. The access modification permission of subclass functions cannot be less than that of the parent class;
If the name, return type, parameter type, and number of the parent class member methods are identical, but their internal code is different, this rewrite method in Java is called member Method refactoring.
Sub-classes can re-adjust the permissions in the parent class method (from small to generous), expand or re-adjust the features of the parent class, and so on, so that the sub-classes are often blue, but better than blue. In the development process, program developers should use these features of sub-classes. However, from another perspective, you also need to restrict the permissions of sub-classes. When necessary, you must control the permissions of some methods in the parent class to prevent abuse of the quilt class.
For more articles about overloading and rewriting of PHP Objects, please follow the PHP Chinese website!