这个重载方法在不同的类和不同的签名中具有相同的名称吗? [英] Is this Overloading, methods with same name in different classes and different signature?

查看:153
本文介绍了这个重载方法在不同的类和不同的签名中具有相同的名称吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在Java中具有以下代码:

If I have the following code in Java:

class A {

    public int add(int a , int b) {
        return (a+b);
    }
}

class B extends A {
    public float add(float a , float b) {
        return (a+b);
}

在这种特殊情况下,子类没有完全覆盖基类的add函数,因为它们具有不同的签名,并且仅当它们在相同范围内时,才会出现重载的概念.那么,子类B中的函数add(float , float)是否被视为一个全新的函数,并且重载和重写的概念不适用于它?并使用静态绑定"还是动态绑定"?

In this particular case the sub-class isn't exactly overriding the base class's add function as they have different signatures and the concept of overloading occurs only if they are in the same scope. So, is the function add(float , float) in the sub-class B treated as an entirely new function and the concept of overloading and overriding is not applicable to it? And does it use 'Static binding' or 'Dynamic Binding'?

推荐答案

类b中的方法add是类a中的重载.不是替代.覆盖只是原始add方法的另一种实现.

Method add in class b is an overload of add in class a. Not an override. An override would just be a different implementation of the original add method.

这篇关于这个重载方法在不同的类和不同的签名中具有相同的名称吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆