Polymorphism is the ability to take many forms. Method overriding is runtime polymorphism.
My questions are:
Is there anything like static polymorphism in Java?
Can method hiding be considered a form of polymorphism?
In this question's answer, it is said that static methods are not polymorphic. What is the reason for that?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With