Why can’t violation parameter types in Java be overridden?
•
Java
Java allows return types to be covariant when overriding superclass methods
Why is it not allowed to use opposite parameter types when overriding methods?
Solution
Because this is called overloading
In particular, the return type can be covariant because it is not considered when overloaded, so it still conforms to the implementation of the superclass or interface Parameters will be considered when overloading You can use number dosomethingwithnumber (integer value) and number dosomethingwithnumber (number value) for optimization
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码