如果Java基础类有一个方法名被“过载”使用多次,在衍生类里对那个方法名的重新定义不会隐藏任何基础类的版本。所以无论方法在这一级还是在一个基础类中定义,过载都会生效。

public class Hide {
    public static void main(String[] args) {
        Bart b = new Bart();
        b.doh(1); // doh(float) used
        b.doh('x');
        b.doh(1.0f);
        b.doh(new Milhouse());
    }
}

class Homer{
    char doh(char c){
        System.out.println("doh(char)");
        return 'd';
    }

    float doh(float f){
        System.out.println("doh(float)");
        return 1.0f;
    }
}

class Milhouse{}

class Bart extends  Homer{
    void doh(Milhouse m){
    }
}

 

相关文章:

  • 2021-11-23
  • 2021-06-11
  • 2022-12-23
  • 2021-12-10
  • 2021-04-09
  • 2022-01-06
  • 2021-09-26
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-04-27
  • 2022-12-23
  • 2022-12-23
  • 2021-09-05
  • 2022-12-23
相关资源
相似解决方案