Overloading: The same class, the function name, the return value or parameter type, the number of different is called overloading.
Overwrite: a function of the same name with the same return value type, called overwrite of the same parameter. Refers to the subclass's override of a method in a parent class.
PHP does not support methods and operator overloading. Java does not support overloading of operators (but "+" is actually an operator overload).
Copy the Code code as follows:
Class Father {
Public Function fmeth1 () {
echo "Fmeth1 () ...
";
}
Public Function Fmeth1 ($str 1) {
echo "Fmeth1 () with $str 1 ...
";
//}
}
Class Son extends Father {
Public Function fmeth1 () {
echo "Fmeth1 () in Son ...
";
}
}
$s =new Son ();
$s->fmeth1 ();
?>
The Fmeth1 method in the parent class is not overloaded.
Cases in Java (overload) overloads and overrides (override) Pee
In the Java language Specification, a method's characteristics include only the name of the method, the number and kind of parameters, not the return type of the method, the name of the parameter, and the exception that was thrown. When the Java compiler examines the overloads of a method, it determines whether two methods are overloaded by these conditions. However, when the Java compiler examines the substitution of a method, it further checks whether the return type of the two methods (sub-type and subtype) is the same as the thrown exception.
QUESTION No:3
Copy the Code code as follows:
Class A {
protected int method1 (int a, int b) {return 0;}
}
Which, valid in a class, that extends Class A? (Choose)
A. public int method1 (int a, int b) {return 0;}
B. private int method1 (int a, int b) {return 0;}
C. private int method1 (int A, long b) {return 0;}
D. public short method1 (int a, int b) {return 0;}
E. static protected int method1 (int a, int b) {return 0;}
310-035 of the questions, the answer is A,c
A is override,access from the protected--->public widened, therefore is correct.
B,d is also override,b from protected--->private narrowing, D return type changed, so all wrong.
C is the overload,access of the width and return type is irrelevant, so is correct.
E is override, but adds static because the static method cannot hide the instance method from super class. So it's wrong.
So choose AC.
Subclasses inherit the parent class and override the parent class method called override-rewrite, overwrite, override
Subclasses have multiple same method names, but different parameters, called overload-Heavy (Zhong) load, overload
Overloads are:
When multiple methods have the same name and have different parameters
Then the different calls to the arguments actually call the different methods
Can also be understood as actually there are two methods, the name is the same, the parameters are different!
Overlay (OVERWRITE) Note
The "visibility of the original method cannot be reduced
The return type does not constitute an override of the method
Heavy Load (overload) note
Overloads can be formed only if the parameters are different
The above describes the allowoverride PHP and Java in the overloaded overload and overrides override introduction, including the allowoverride aspect of the content, I hope to be interested in PHP tutorial friends helpful.