当前位置:网站首页>rewrite? Reload? Are you dizzy?

rewrite? Reload? Are you dizzy?

2022-06-22 09:13:00 C_ x_ three hundred and thirty

public class CCC {
    public static void main(String[] args) {
    }

}
class A{
    public A foo() {
        return this;
    }
}
class B extends A {
    public A foo(){
        return this;
    }
}
class C extends B {
    public void foo(){}
    //  The method name is the same , The same goes for the parameter list -> Overload is not satisfied ; The method name is the same , Different return types , Does not satisfy rewriting -> Report errors 

    public int foo(){return 1;}
    //  The method name is the same , The same goes for the parameter list -> Overload is not satisfied ; The method name is the same , Different return types , Does not satisfy rewriting -> Report errors 

    public A foo(){return A;}
    //  The method name is the same , The same goes for the parameter list -> Overload is not satisfied ; The method name is the same , The return type is less than or equal to the return type of the parent class , Satisfy rewrite ;
    //  But the format is wrong   should  return new A();

    public A foo(B b){return b;}
    //  The method name is the same , The parameter list is different -> Meet heavy load ; Different parameter types , So it's not rewriting ;
}

Method rewriting  

rewrite The principle of "two identical, two small and one big" is required , Same method name ,

原网站

版权声明
本文为[C_ x_ three hundred and thirty]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/173/202206220910015247.html