I have a class of a binary search tree:
class BSTree<T> {
...
protected void insert(BSNode<T> parent, int side, BSNode<T> child){
... // Binary tree insertion logic
}
public void add(T data){
...
parent, side, child = search(data) // this line is pseudo code
insert(parent, side, child) // instance insertion logic
}
...
}
My tree's nodes are instances of the BSNode
class.
I am implementing an extending class of the BSTree
- the AVLTree
class, which is using an extension of the BSNode
- AVLNode extends BSNode<Integer>
This is the AVLTree
class:
class AVLTree extends BSTree<Integer>{
...
/* overrides BSTree insert() with slightly different parameters,
which inherit from the parameters of the BSTree insert() method */
protected void insert(AVLNode parent, int side, AVLNode child){
... // AVL tree insertion logic
}
...
}
My question is:
I want the insert()
method in AVLTree
to override the insert()
method in BSTree
, so that when called from within add()
, the correct method will be called based on the object's class.
How can I override the method insert
from the BSTree
class inside AVLTree
to take AVLNode
s as arguments?