The difference between Overload and Override. Can overload methods be differentiated based on the return type ?, Overloadoverride
Both overloading and rewriting are the embodiment of polymorphism. The difference is that overloading is the polymorphism at compilation and rewriting is the polymorphism at runtime;
Overload: only occurs in one class. It is distinguished by the same name of the method and different parameter types or number of parameters.
Rewriting: between the parent class and the subclass, rewriting requires that the override method of the subclass must have the same return type as the override method of the parent class, which is better accessed than the method of the parent class, it cannot declare more exceptions than the method whose parent class is overwritten, but the overload does not have special requirements for the return type.
Can overload methods be differentiated based on the return type?
No. If the return type is used to distinguish public void test1 () {}and publiv String test1 () {return "" ;}( compilation failed) in the same class) if the compilation is successful, the class is used when the method is proposed. test1 cannot identify which method is called
This article is taken from the JAVA interview book