To answer your questions:
- The ability to select more specialized methods at runtime depending on the object used to call it.
- Of course. Polymorphism can occur without the participation of abstract classes.
- No, overloading / overriding are not types of polymorphism.
, .
class A
{
public void a()
{
System.out.println("Hello from A");
}
}
class B
extends A
{
@Override
public void a()
{
System.out.println("Hello from B");
}
}
class C
{
public static void SomeStatic(A a)
{
a.a();
}
}
C , SomeStatic B. A, A A. B, B A. , .
- . , , . . , .
, , () . . ( ).
C - :
class Main
{
public static void main(String[] args)
{
A a = new A();
B b = new B();
C.SomeStatic(a);
C.SomeStatic(b);
}
}
Poly: . .
: . .
, "many" (poly) "forms" (morph) . , , .