Is method hiding a form of Polymorphism?

后端 未结 5 1872
夕颜
夕颜 2021-01-03 04:06

Polymorphism is the ability to take many forms. Method overriding is runtime polymorphism.

My questions are:

  1. Is there anything like static polymor

5条回答
  •  半阙折子戏
    2021-01-03 04:13

    If we run this test

    class A {
        static void x() {
            System.out.println("A");
        }
    }
    
    class B extends A {
        static void x() {
            System.out.println("B");
        }
    }
    
    class Test {
        public static void main(String[] args) throws Exception {
            A a = new B();
            a.x();
        }
    }
    

    it will print A. If method x() were polymorphic, it would print B.

提交回复
热议问题