In a binary search tree all the nodes in left sub-tree have smaller or equal key than the parent's key and all the nodes in right sub tree have greater key than the parent node's key.
class BST{
.....
.....
public int getSecondMaxKey(){
BST lastNode = null;
BST secondLastNode = null;
BST next = null;
while(this.rightChild != null){
secondLastNode = lastNode;
lastNode = this;
this = this.rightChild;
}
return secondLastNode;
}
}