Question No: 3
1. Class {
2. Protected int Method1 (int A, int B) {return 0 ;}
3 .}
Which two are valid in a class that extends Class? (Choose two)
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 ;}
The standard answer for the question in 310-035 is a, c
A is not an overload, and A is a rewrite! That is, overwrite!
Overwrite cannot reduce the "visibility" of the original method"
Class {
Protected int Method1 (int A, int B) {return 0 ;}
}
Class B extends {
Public int Method1 (int A, int B) {return 0 ;}
}
Then there is only one Method1 (INT, INT) method in B!
--------------------------------------------
Reload is:
When multiple methods have the same name and contain different parameters
Different methods are called for different parameters.
It can also be understood that there are actually two methods with the same name and different parameters!
Class {
Protected int Method1 (int A, int B) {return 0 ;}
}
Class B extends {
Private int Method1 (int A, long B) {return 0 ;}
}
B has two methods: Method1 (INT, INT) and Method1 (INT, long!
Because "yes" is two methods
Class B extends {
Public int Method1 (int A, long B) {return 0 ;}
}
It is also correct
-------------------------------------------------------------------------
-------------
Note:
Overwrite (do not know if it is overwrite) Note
The "visibility" of the original method cannot be reduced"
Heavy Load (not just overload)
Overload can be formed only when parameters are different. "visibility", and different return types cannot constitute overloading of methods.
Overload is not:
Re-write (load)
Reload is:
Multiple (possible) Loads