×

Loading...

Let me try.

Let me try to explain in English. I try to make things simple and hope it will be a little help for you and not make you confuse more.

As far as I know, virtual function is used in C++ to realize the polymorphism, not in Java. So I do not disccuss about virtual function here. But it is definitely helpful for you to understand polymorphism if you understand virtual function in C++.

Simply to say, polymorphism in Java is one way that enables you to define methods with objects (let us call them object parameter) as their parameters and you can pass any objects which is in the inheritant tree rooted from an object parameter to the methods.

For example:

base calss A;
derived class B : A;
derived class C : A;

class D {
method(A a) {
...;
}
}

You can call D::method(A a) as following:

B b;
C c;
D d;
d.method(b);
d.method(c);
Sign in and Reply Report