What is the difference between overload and override in Java interview questions? Can the overload method change the type of return value?

1. What is the difference between overload and override?

  • overload: overload: in the same class, the method name is the same, but the parameter list is different. It has nothing to do with the return value type.
  • override: Override: exists in the child parent class, or child parent interface, the method name is the same, and the parameter list is the same.

The rewrite follows the principle of two same two small ones:

  1. Two same: the method name is the same, and the parameter list is the same.

  2. Two small:

    • Types of:
      • Basic type: The return value type of the subclass must be equal to the return value type of the parent class.
      • Reference type: The return value type of the child class is less than or equal to the return value type of the parent class.
    • Exception: the exception thrown by the subclass is less than or equal to the exception thrown by the parent class
  3. One: The access rights of the subclass are greater than or equal to the access rights of the parent class

2. Can the overload method conceptualize the return value type?

You can change the type of the return value because it has nothing to do with the return value type.

Guess you like

Origin blog.csdn.net/weixin_44296929/article/details/108317581