It should be emphasized that polymorphism occurs only in methods, but not in domains. For methods, only non-static and non-final methods have polymorphism.
The static method does not have polymorphism. it is worth noting that the so-called static method cannot be polymorphism: whether the override method itself is static, not whether the method that calls the override method is static!
For example, the following program:
Class father ...{
Public void act ()...{
System. Out. println ("father. Act ()");
}
}
Class son extends father ...{
Public void act ()...{
System. Out. println ("son. Act ()");
}
}
Public class test ...{
Public static void test (father I )...{
I. Act ();
}
Public static void main (string [] )...{
Son son = new son ();
Test (son );
}
}
The output result is son. Act (). If static cannot be polymorphism, shouldn't it be father. Act?
In fact, as mentioned above, we should consider whether the Act () method is static, whether there is polymorphism, rather than whether the called method test () is static.
This is irrelevant to whether the test method is static. If both act methods are modified to static, the output result is Father. Act (), because the static method cannot be polymorphism.