I have an interface called Dictionary which has a method insert(). This interface is implemented by class BSTree, but I also have a class AVLTree which is a child class of BSTree. AVLTree redefines the insert() so it suits it’s needs. Now if I type the following code:
Dictionary data=new AVLTree(); data.insert();
There is a problem, because the insert() method that is called is of BSTree instead of AVLTree. Why doesn’t the polymorphism kick in here? What is the appropriate solution, one that retains the principle of polymorphism?
In java, (I’m talking relatively to C++), polymorphism should ‘always’ work. It’s hard to see what’s wrong without looking at the code.. maybe you could post interesting part? Such as the method’s signature, class declaration, etc.. My guess is that you haven’t used the same signature for both methods.